I upgrade my system to ubuntu 18.04 lts, but I work on projects that require JDK 7. How can i install jdk7 on ubuntu 18.04 lts 64bit?
3 Answers
Download the JDK for Linux 32-bit or 64-bit (for example: jdk-7u80-linux-x64.tar.gz
)
Navigate to
~/Downloads
:cd /home/"your_user_name"/Downloads
Create a a directory in
/usr/local
wherejava
will reside and copy tarball there:sudo mkdir -p /usr/local/java sudo cp -r jdk-7u80-linux-x64.tar.gz /usr/local/java/
Navigate to
/usr/local/java
:cd /usr/local/java
Extract the tarball:
sudo tar xvzf jdk-7u80-linux-x64.tar.gz
Check if tarball has been successfully extracted:
ls –a
You should see
jdk1.7.0_80
.Open
/etc/profile
withsudo
privileges:sudo nano /etc/profile
Scroll down to the end of the file using arrow keys and add the following lines below at the end of
/etc/profile
file:JAVA_HOME=/usr/local/java/jdk1.7.0_80 JRE_HOME=/usr/local/java/jdk1.7.0_80 PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin export JAVA_HOME export JRE_HOME export PATH
Update alternatives:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_80/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_80/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_80/bin/javaws" 1 sudo update-alternatives --set java /usr/local/java/jdk1.7.0_80/bin/java sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_80/bin/javac sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_80/bin/javaws
Reload profile:
source /etc/profile
Verify installation:
java -version
You should receive a message which displays:
java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
-
Thank you, i used your instructions to install JDK8 and it worked well. Thanks! A few minor points though: If i try to download JDK7 it wants me to log in to an Oracle account. Also steps 8-14 are only needed if the user already has Java installed– sunyataAug 2, 2018 at 12:10
-
2
-
-
1
Update -
Since the bottom fix is no longer working, try this -
- Visit http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
- Download the desired java package. i.e, 32bit(x86) or 64bit(x86_64)
note: you'll need to sign in to download it as pointed by @Kendzi in the comment below - Change location to your downloads folder(or to where you've download the archive)
cd ~/Downloads
- Extract the archive
tar -xvzf jdk-7u80-linux-x64.tar.gz
- There should be a new folder available now, named - jdk1.7.0_80 or something similar
- Move the folder to a desired location.
Move it to the default location(recommended) -sudo mv jdk1.7.0_80 /usr/lib/jvm/
note : create the jvm folder if it does not exist withsudo mkdir /user/lib/jvm
- Assuming the folder has now been moved to /usr/lib/jvm,
- If this is the absolute first time you're installing Java, just run the update-alternatives command to update the preferred Java as default
update-alternatives --config java
and select the option number for Java 7 - if you have already installed Java once check whether a symlink exists in /etc/alternatives
sudo ls -al /etc/alternatives/java
If you see a listing similar to the followinglrwxrwxrwx 1 root root 46 Jun 20 21:51 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
The symlink exists and only needs to be updated using the command -update-alternatives --config java
This will list the available Java executable files available in your system, like so -
(including the JDK 7 executable you've placed in /usr/lib/jvm) Note the asterisk(*) next to option 1. This indicates the default version of Java being used.
If the JDK 7 location is listed here, enter the option number and hit enter to set JDK 7 as the default. - If for some reason no listing is provided after running the update-alternatives command, check if the symbolic links(symlink) are setup properly
sudo ls -al /etc/alternatives/java
if no file is found, create the symlink -sudo ln -s /etc/alternatives/java /usr/lib/jvm/jdk1.7.0_80/bin/java
Also, create a symlink in /usr/bin to ensure availability of the Java executable in the terminal. So first check if the file exists in /usr/local-sudo ls -al /usr/bin/java
if no file is found, create the symlink -sudo ln -s /usr/bin/java /etc/alternatives/java
- If this is the absolute first time you're installing Java, just run the update-alternatives command to update the preferred Java as default
- Finally set the JAVA_HOME variable for application use by editing file /etc/environment
sudo gedit /etc/environment
and add the JAVA_HOME variable like so -JAVA_HOME="/usr/bin/java"
save and close the file.
Reload the environment file using command -source /etc/environment
(Fix is no longer working as noted by @Christian Rodriguez)
After downloading the the Oracle JDK 7 package from Oracle's website, place the file in the location -
/var/cache/oracle-jdk7-installer/<Oracle JDK 7>
(create the oracle-jdk7-installer
folder if it is not already present)
Then open a terminal(shortcut: Ctrl+Alt+t
) and execute each of the following commands(one after the other) -
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
To verify the installation was successful, execute the following command -
java -version
You should see a message similar to the one shown below -
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)
Refer
- http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
- http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html
for more information.
-
1
Looks like regular JDK are only available to Oracle Customers after creating account:
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
But that link is still working:
http://www.oracle.com/technetwork/java/javaee/downloads/java-ee-sdk-7-jdk-7u21-downloads-1956231.html
Simply chose "java_ee_sdk-7-jdk7-linux-x64.sh" and install it manually.
-
-
- mark it as executable
chmod +x java_ee_sdk-7-jdk7-linux-x64.sh
and run it by./java_ee_sdk-7-jdk7-linux-x64.sh
that run UI with wizzard– KendziMay 10, 2018 at 9:27 -
-
1You need to open terminal, go to directory where you downloaded file and execute command:
chmod +x java_ee_sdk-7-jdk7-linux-x64.sh
later run install with executing second command./java_ee_sdk-7-jdk7-linux-x64.sh
– KendziMay 10, 2018 at 9:51 -
when i run ../java_ee_sdk-7-jdk7-linux-x64.sh i get the folloing error :Could not locate a suitable jar utility. Please ensure that you have Java 7 or newer installed on your system and accessible in your PATH or by setting JAVA_HOME– sanaMay 10, 2018 at 10:11