If you're using Ubuntu Linux on your daily basis work, you've probably Java installed on your machine. Personally I prefer using Wepupd8 PPA to manage JAVA installation, it makes my life a lot more easier especially for updates. The Wepupd8 team didn’t add any binary for Oracle JAVA installation and they made a script to download the Oracle JAVA from Oracle website and install it straight away. So whenever Oracle will release the update, I can simple upgrade via package manager.
Working with multiple Java versions in your machine is a normal thing, especially if you're a Java developer, and because I'm a (very) lazy person, I'm always looking for a quicker/easier way to make the switch.
Today, I'll share with you my tip on this subject. First, let's run the following command:
$ sudo update-alternatives --config java
Running this command shows a list of installed Java JDKs and JREs allowing one to be selected as the default that is used when java needs to be executed.
But I'm using it just to get the Installation path of each Java version.
Then, for each version I created a script that contain the following lines (in the example below, I'm showing the one for java 8):
Note that I'm using u8.sh to make he switch to Java 8, and u9.sh for Java 9 and so on.
The final step is to add an alias in ~/.bashrc file to source our script as follow:
The final step is to add an alias in ~/.bashrc file to source our script as follow:
and That's all. Now for switching between Java versions, I only run u8, u7 or u9 ;)
沒有留言:
張貼留言