Changing Java version using alias in Linux
As a programmer or a user there may be times that you might need to switch between different java
versions in order for running some legacy softwares or for testing your own written programs. With Linux this can be done easily and effectively. Please go through the following steps in changing your java
version temporary. (please do note that this change is effective only for the terminal that executed the alias)
- First download the relevant JDK (Java Development Kit) you need from Oracle Website.
- Then extract the downloaded JDK to a desired location.
- Open
.bashrc
from your favorite text editor. (in my case it’s Vim)
vim ~/.bashsrc
then at the bottom of the file add the following lines and save the file.
alias java7 = 'export JAVA_HOME="/path/to/your/jdk/location" ; export path=$JAVA_HOME/bin:$path'
- Finally source the new configurations by running the following
source ~/.bashrc
All are set :) now you will be able to switch between Java
versions just by running the alias word on your terminal.
echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
java7
echo $JAVA_HOME
/home/kasun/Downloads/Softwares/Java/Java-7/jdk1.7.0_80/
Note: you can have as mush as java
versions like above with different aliases.