How can I install the latest version of Sun Java (JRE)? [duplicate]
I want to install Oracle's JRE and to update to the latest version with the Software Updater when they released. Is there a Ubuntu package that is provided by Canonical or Oracle?
Before release Java 7, I followed this way to install Java 6.
But it doesn't work for Java 7. There is no package sun-java7-xxx
. How can you install Java 7?
Solution 1:
There is a similar answer on how to install JRE 7.
Install Java JDK
The manual way
Download the 32-bit or 64-bit Linux "compressed binary file" - it has a ".tar.gz" file extension.
-
Uncompress it
tar -xvf jdk-8-linux-i586.tar.gz
(32-bit)tar -xvf jdk-8-linux-x64.tar.gz
(64-bit)The JDK 8 package is extracted into
./jdk1.8.0
directory. N.B.: Check carefully this folder name since Oracle seem to change this occasionally with each update. -
Now move the JDK 8 directory to
/usr/lib
sudo mkdir -p /usr/lib/jvm sudo mv ./jdk1.8.0 /usr/lib/jvm/
-
Now run
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0/bin/javaws" 1
This will assign Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default. Be sure to use a higher priority if you want Oracle JDK to remain the default.
-
Correct the file ownership and the permissions of the executables:
sudo chmod a+x /usr/bin/java sudo chmod a+x /usr/bin/javac sudo chmod a+x /usr/bin/javaws sudo chown -R root:root /usr/lib/jvm/jdk1.8.0
N.B.: Remember - Java JDK has many more executables that you can similarly install as above.
java
,javac
,javaws
are probably the most frequently required. This answer lists the other executables available. -
Run
sudo update-alternatives --config java
You will see output similar to the one below - choose the number of jdk1.8.0 - for example
3
in this list (unless you have have never installed Java installed in your computer in which case a sentence saying "There is nothing to configure" will appear):$ sudo update-alternatives --config java There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode * 2 /usr/lib/jvm/jdk1.7.0/bin/java 1 manual mode 3 /usr/lib/jvm/jdk1.8.0/bin/java 1 manual mode Press enter to keep the current choice[*], or type selection number: 3 update-alternatives: using /usr/lib/jvm/jdk1.8.0/bin/java to provide /usr/bin/java (java) in manual mode
Repeat the above for:
sudo update-alternatives --config javac sudo update-alternatives --config javaws
Note for NetBeans users!
You need to set the new JDK as default editing the configuration file.
If you want to enable the Mozilla Firefox plugin:
32 bit:
ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/
64 bit:
ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
N.B.: You can link the plugin (libnpjp2.so
) to /usr/lib/firefox/plugins/
for a system-wide installation (/usr/lib/firefox-addons/plugins
from 15.04 onwards). For Ubuntu 13.10, the path to the plugin directory is /usr/lib/firefox/browser/plugins/
.
Depending on your configuration, you might need to update the apparmor profile for Firefox (or other browsers) in /etc/apparmor.d/abstractions/ubuntu-browsers.d/java
:
# Replace the two lines:
# /usr/lib/jvm/java-*-sun-1.*/jre/bin/java{,_vm} cx -> browser_java,
# /usr/lib/jvm/java-*-sun-1.*/jre/lib/*/libnp*.so cx -> browser_java,
# with those (or adapt to your new jdk folder name)
/usr/lib/jvm/jdk*/jre/bin/java{,_vm} cx -> browser_java,
/usr/lib/jvm/jdk*/jre/lib/*/libnp*.so cx -> browser_java,
Then restart apparmor:
sudo /etc/init.d/apparmor restart
The easy way (Obsolete)
Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists because of hostorical reasons.
The easiest way to install the JDK 7 is to do it with the Web Up8 Oracle Java OOS. However, it is believed that this PPA is sometimes out of date. Also note the dangers of using a PPA.
This installs JDK 7 (which includes Java JDK, JRE and the Java browser plugin):
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
# or if you want JDK 8:
# sudo apt-get install oracle-java8-installer
# these commands install Oracle JDK7/8 and set them as default VMs automatically:
# sudo apt-get install oracle-java7-set-default
# sudo apt-get install oracle-java8-set-default
Source
N.B.: Before someone screams this is against the Oracle redistribution license - the PPA does not actually have Java in the personal repository. Instead, the PPA directly downloads from Oracle and installs it.
The Script way
If you're on a fresh installation of Ubuntu with no previous Java installations, this script automates the process outlined above if you don't want to type all that into a console. Remember, you still need to download Java from Oracle's website -- Oracle's links are not wget
friendly.
Before using this make sure that this script is in the same directory as the .tar.gz
file extension that you downloaded and there are no files that start with jdk-7 in the same folder. If there are, please move them out of the folder temporarily. Remember to make the script executable (chmod +x <script's file>
).
#!/bin/sh
tar -xvf jdk-7*
sudo mkdir /usr/lib/jvm
sudo mv ./jdk1.7* /usr/lib/jvm/jdk1.7.0
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
If you want to install the plugin for Firefox then add this to the end of the script:
mkdir ~/.mozilla/plugins
ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
sudo /etc/init.d/apparmor restart
Check if installation was successful
You can check if the installation succeeded with the following command:
java -version
You should see something like
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
You can check if the JRE Mozilla plugin has been successful by using the official oracle website.
For Java 6: How do I install Oracle JDK 6?
Solution 2:
There is a similar answer on how to install JDK 8
Install the JRE
Download the 32-bit or 64-bit Linux "compressed binary file" - it has a ".tar.gz" file extension and uncompress it
tar -xvf jre-7-linux-i586.tar.gz
The JRE 7 package is extracted into ./jre1.7.0 directory. Now move the JRE 7 directory to /usr/lib
:
sudo mv ./jre1.7.0* /usr/lib/jvm/jre1.7.0
Afterwards, run the following to get a list of currently installed Java alternatives.
sudo update-alternatives --config java
You will get output as:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
Press enter to keep the current choice[*], or type selection number:
Remember the last number and press enter to exit this utility i.e. in this example remember the number 2
.
If only one alternative is shown then remember the number 0
.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jre1.7.0/bin/java 3
This will add your new JRE 7 installation into the alternatives list i.e. use the remembered number + 1, that is, 3 in the example above. Now configure Java to use the Oracle Java JRE:
sudo update-alternatives --config java
You will see output similar one below - choose the number of jre1.7.0, that is, 3
:
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
3 /usr/lib/jvm/jre1.7.0/jre/bin/java 3 manual mode
Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jre1.7.0/jre/bin/java to provide /usr/bin/java (java) in manual mode.
N.B.: If there was no previous Java installation then the new JRE will be the default and you will not see the above.
Check the version of you new JRE 7 installation:
java -version
It should produce
java version “1.7.0”
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)
Install the Firefox/Chrome plugin
In a terminal:
mkdir ~/.mozilla/plugins
Remove the IcedTea plugin, if it has been installed.
sudo apt-get remove icedtea6-plugin
Remove a former version of the Java plugin (may or may not be present):
rm ~/.mozilla/plugins/libnpjp2.so
Now you can install the plugin, by creating a symbolic link (you tell Firefox, where the plugin is located). For 32-bit Java use
ln -s /usr/lib/jvm/jre1.7.0/lib/i386/libnpjp2.so ~/.mozilla/plugins/
For 64-bit Java use
ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
Confirm that the JRE has been successful by using the official oracle website.
Solution 3:
Here is a tested and working solution for installing Oracle JDK 7 and all its files so "javac" and everything else works: How To Install Oracle Java 7 (JDK) In Ubuntu
Here are the commands (just for convenience):
- Download the latest Oracle JDK 7 from here.
- Extract the downloaded Oracle Java JDK archive in your home folder - a new folder called "jdk1.7.0_03" (for Java JDK7 update 3) should be created. Rename it to "java-7-oracle" and move it to /usr/lib/jvm using the following commands:
cd sudo mkdir -p /usr/lib/jvm/ #just in case sudo mv java-7-oracle/ /usr/lib/jvm/
3. Install Update Java package created by Bruce Ingalls (packages available for Ubuntu 11.10, 11.04, 10.10 and 10.04):
sudo add-apt-repository ppa:nilarimogard/webupd8 sudo apt-get update sudo apt-get install update-java
4. Now run the following command in a terminal to install Oracle Java JDK:
sudo update-java
After a few minutes, Oracle Java JDK should be successfully installed on your Ubuntu machine. You can check out the version by running these commands in a terminal:
java -version javac -version
NOTICE! This part below here of this answer no longer works due to Java changing how their binaries are released. It has been left as-is for historical reasons.
Update Oracle has released Java 8 (stable). To install it, use the following commands:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
More information @ WebUpd8: Install Oracle Java 8 In Ubuntu Via PPA Repository [JDK8]
Solution 4:
NOTICE! This solution no longer works due to Java changing how their binaries are released. As a result, this answer is no longer valid. It has been left as-is for historical reasons.
From http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html :
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-jdk7-installer
- Are PPAs safe to add to my system and what are some "red flags" to watch out for?