table of Contents
Download the installation package
First official website to download the installation package.
installation
input the command
chmod 777 jdk-6u45-linux-x64.bin
sudo ./jdk-6u45-linux-x64.bin
Move to the specified location and set the version
Create a new folder in java / usr / lib directory, installed in the previous step to move to the next folder in the directory
cd /usr/lib
sudo mkdir java
sudo mv jdk1.6.0_45/ /usr/lib/java
Then enter the following three commands
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/jdk1.6.0_45/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk1.6.0_45/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/jdk1.6.0_45/bin/javaws" 1
Each of the last command 1
is the priority when there are multiple versions of the system at the same time jdk
Set Environment Variables
sudo gedit ~/.bashrc
In the end of the file plus
#JAVA HOME directory setup
export JAVA_HOME=/usr/lib/java/jdk1.6.0_45
export PATH="$PATH:$JAVA_HOME/bin"
Save and exit, enter java -version
test.
Note: Some online tutorials final step is to modify /etc/profile
, I appeared that way path system commands can not find, can not lead to reboot into the system need to reinstall the system.
Switching java version
Sometimes there may be multiple versions of java inside the system, you can select the version they need through the following command.
sudo update-alternatives --config java