Reputation: 1461
Previously, there was an easy way to install Java 8 on Ubuntu using webupd8team
repository. But currently it does not work and packages are not located.
Upvotes: 1
Views: 2001
Reputation: 1461
So after spending a lot of effort on such a common case I decided to add this post. I used several resources to achieve it.
sudo apt-get purge openjdk*
sudo mkdir /usr/lib/jvm-oracle
sudo cp ~/Downloads/(name of your tarball) /usr/lib/jvm-oracle
cd /usr/lib/jvm-oracle
sudo tar -xvzf (name of tarball)
cd jdk1.8.0_(corresponding version)
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm-oracle/jdk1.8.0_{version}/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm-oracle/jdk1.8.0_{version}/bin/javac 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm-oracle/jdk1.8.0_{version}/bin/javaws 1
sudo cat > /etc/profile.d/jdk.sh
export JAVA_HOME="/usr/lib/jvm-oracle/jdk1.8.0_221"
export PATH="$PATH:${JAVA_HOME}/bin"
Ctrl+d
sudo update-alternatives --config java
You can download Java from here
Upvotes: 2
Reputation: 660
Download the JDK 8 SDK.
Create a directory at /usr/lib called jvm-oracle
. You will need to use the sudo command as this directory is at root level:
sudo mkdir /usr/lib/jvm-oracle
Copy your tarball over:
sudo cp ~/Downloads/(name of your tarball) /usr/lib/jvm-oracle
Move into the /usr/lib/jvm-oracle and extract your tarball:
Move into: cd /usr/lib/jvm-oracle
Extract: sudo tar -xvzf (name of tarball)
List out the directory contents and find your extracted folder: ls -al
You should see a directory like ‘jdk1.8.0_172’. Move into your dir and the bin folder with cd and list out the contents.
Move to new dir: cd jdk1.8.0_172.
Move to bin: cd bin
List out Contents: ls -al
Run these following commands:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm-oracle/jdk1.8.0_172/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm-oracle/jdk1.8.0_172/bin/javac 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm-oracle/jdk1.8.0_172/bin/javaws 1
Then add the JAVA_HOME by these command:
echo $'\nJAVA_HOME='`which java` >> ~/.bashrc
Alternatively, you can add it manually by opening your .bashrc file and setting
JAVA_HOME=/usr/bin/java
Upvotes: 1