What to do if you have installed Java for OS X on macOS

If you have installed JDK6 on macOS Sierra or OS X El Capitan using Java for OS X, it was quite difficult to remove it cleanly, so make a note.

environment

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.12
BuildVersion:	16A323

problem

The question "what's wrong?" Is that you can't change the symbolic links created when you install Java for OS X (ln -fs, ʻunlink, rm`).

The symbolic link in question is below.

$ ls -al /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
lrwxr-xr-x  1 root  wheel  59  1 27 01:03 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ->  /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

This doesn't disappear easily. The ln command seems to pass and does not change, and the ʻunlink and rm` commands return Permission denied.

Cause

After investigating, it seems that the cause was that protection by a function called SIP (System Integrity Protecton) implemented after ʻOS X El Capitan` was working.

There were people who were having trouble with the same thing on stackexchange, so it was very helpful. => [delete-unnecessary-files-in-system-library-for-mac-os-x](http://apple.stackexchange.com/questions/214538/delete-unnecessary-files-in-system-library- for-mac-os-x)

Solution

Once you know this, it's not that difficult to deal with later. Follow the steps below.

  1. Start restarting your Mac and press and hold + r before booting.
  2. Make sure the macOS utility starts.
  3. From the menu, open Utilities> Terminal.
  4. In an open terminal, type csrutil disable to run it. (This command disables SIP.)
  5. After confirming the execution, reboot as usual.
  6. After rebooting, open the terminal again and ʻunlink` the target symbolic link or delete the linked directory.
  7. After deleting, if there is a path of the JDK you want to switch to, make a symbolic link to /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK.

that's all. After all the operations, it is recommended to start macOS utility again and run csrutil enable to enable SIP just in case.

If you want to install JDK6

Let's install it with Homebrew. You can install JDK6 with the following command.

However, even with this method, /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK may be overwritten, so it may be better to prepare for checking the path of the symbolic link and replacing it. not.

$ brew cask install java6

$ ls /Library/Java/JavaVirtualMachines/
1.6.0.jdk/        jdk1.7.0_79.jdk/  jdk1.8.0_121.jdk/ jdk1.8.0_91.jdk/

$ ls -al /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
8 lrwxr-xr-x  1 root  wheel  59  2  4 20:11 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK -> /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents 

$ sudo unlink \
> /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

$ sudo ln -s \
> /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents \
> /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

Recommended Posts

What to do if you have installed Java for OS X on macOS
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if you install Ubuntu
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if you get an error on heroku rake db: migrate
What to do if you get angry if you don't have nokogiri while installing wp2txt
What to do if TextToSpeech doesn't work on Android 11
What to do if you accidentally create a model
What to do if you get a port error when docker-compose up on Mac
What to do if you cannot execute with the command "Java package name / class name"
What to do if you can't find the JDK you put in SDKMAN after migrating from bash to zsh on macOS
What to do if you get a java.io.IOException in GlassFish
What to do if audio is not available on discordrb
# What to do if you accidentally do rails db: migrate: drop
What to do if you can't use the rails command
[Java] [Spring] What to do if you cannot Autowire with Type Mismatch after annotating Spring Security
What to do if you enable UFW on Ubuntu VM on GCP and you can't connect to SSH
What to do if you installed Ruby with rbenv but the version does not change
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
What to do if you get angry with OpenSSL with pyenv install
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
What to do if you go offline due to SSL certificate error when running Jenkins on Mac
[Spring Boot] What to do if an HttpMediaTypeNotAcceptableException occurs on an endpoint for which produces is set
What to do if you get "Changes not staged for commit:" when you git status after git add.
How to check Java installed on Mac
If you can't install java on Catalina
What to do if you get a groovy warning in Thymeleaf Layout
What to do if you get an error during rails db: reset
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if you get an uninitialized constant Likes Controller error
What to do if you can't install the plugin from the Eclipse marketplace
What to do if deployment fails on Heroku (Ruby app not detected)
no space left on device What to do if an error occurs
What to do if you don't like the code generated by swagger-codegen-cli
What to do if you get an error when you hit Heroku logs
What to do if you get the error Too long with no output (exceeded 10m0s) on CircleCI
What to do if you have enabled Use the WSL2 based engine in Docker Desktop with insufficient WSL2 installation
How to translate the error message into Japanese (What to do if you cannot log in for some reason)
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
What to do if you get Could not locate Gemfile or .bundle / directory
What to do if you can't activate the select box created by bootstrap-select
What to do if you get the error message unrecognized selector send to instance "***"
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
What to do if Docker Desktop fails to launch on your M1 MacBook Pro
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
What to do if the rails server doesn't run out on AWS cloud9
What to do if the server tomcat dies
[Java] (for MacOS) How to set the classpath
What to do if mvn archetype: generate fails
What do you use when converting to String?
What to do if you switch Java versions on Windows 7 and get Error: Registry key'Software \ JavaSoft \ Java Runtime Environment'\ CurrentVersion' has value '1.8', but '1.7' is required.
What to do if you get a wrong number of arguments error in binding.pry
What to do if you can't get the text of an element in Selenium
You don't have to write for twice when you make a right triangle in Java
What to do if you get the error Couldn't find Item without an ID
What to do if you can't find your API key after deploying to Rails heroku