Install Custom Java version in Linux
Posted By : Kamaldeep Singh | 12-Jan-2017

Hi folks, I have seen many a times that there is project requirement to use some old java version installation but as your system is already upgraded to the latest version you find it difficult to install it in one go. Most important, you don't need to worry about your default installation. So follow the below steps to install the required version of java in your system:
Step 1: Download the required version of JDK from the following link:
http://www.oracle.com/technetwork/java/archive-139210.html#javase
Here select the major version of JDK and on the next page download the specific minor version of the selected major version like "Java SE Development Kit 7u51" to download JDK 7u51. Make sure to accept the License Agreement and then download the .tar.gz extension file against the Linux platform. I assume that you have downloaded the JDK in the /home/user/Downloads directory.
Step 2: Now extract the .tar using the following command in your /home/user/Downloads directory
tar -xvzf [your_file_name]
Example:
tar -xvzf jdk-8-linux-x64.tar.gz
Step 3: Create jvm folder in /usr/lib, if jvm folder doesn't exist using the following command:
sudo mkdir /usr/lib/jvm
Step 4: Move the extracted jdk folder to /usr/lib/jvm location. Follow the command being in your /home/user/Downloads directory
sudo mv {your_folder_name} /usr/lib/jvm
Step 5: Install the java source in system:
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/{your_folder_name}/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/{your_folder_name}/bin/java 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/{your_folder_name}/bin/javaws 1
Example:
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0/bin/javac 1 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0/bin/java 1 sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.8.0/bin/javaws 1
Step 6: Now following are the major steps which help you to switch your java version at any point of time. To choose the default java follow these commands to select the java, javac or the javaws version:
sudo update-alternatives --config javac sudo update-alternatives --config java sudo update-alternatives --config javaws
Running these individual commands will ask you for the version of java. Type in the number against the java version which you want and press enter. Make sure that you select the same java version in all the configuration selection.
Step 7: Test the java version by running the following command:
java -version
It will give you the default version of java used by the system.
Step 8: Configure JAVA_HOME. Type the following command in your terminal:
sudo gedit /etc/profile
Add following lines in end:
JAVA_HOME=/usr/lib/jvm/{your_folder_name}
export JAVA_HOME
Example:
JAVA_HOME=/usr/lib/jvm/jdk1.7.0 export JAVA_HOME
Step 9: Restart your system or you can load your updated source file by running the below command
source /etc/profile
Thats all for now. Write comments for any queries.
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Kamaldeep Singh
Kamaldeep is a highly skilled Backend Developer specializing in Java, specifically the Spring framework. He also has extensive knowledge of Javascript and associated frameworks such as Node.js and Express. He possesses a deep understanding of the latest technologies and has hands-on experience with Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as both relational databases like MySQL and PostgreSQL and non-relational databases like MongoDB. He has made significant contributions to various projects, including Viral Nation, ExamWorks, TNIBRO, Biogas engineering, SecureNow - Web Application, FB Messenger Chatbot, Dialogflow Chatbot, and Catalyst. Kamaldeep's expertise allows him to seamlessly integrate different technologies into applications, highlighting his adaptability and innovative mindset. His practical experience and strong technical skills make him an invaluable asset to any team.