- How to set JAVA_HOME for Java?
- Linux jdk home directory
- General Notes About Installing the JDK on Linux Platforms from Archive Files
- General Notes About Installing the JDK on Linux Platforms from RPM packages
- System Requirements for Installing JDK on Linux Platforms
- Installing the JDK on Linux from Archive Files, RPM Packages and Oracle Linux Repositories
- Installing the 64-Bit JDK on Linux Platforms
- Installing the 64-Bit JDK on RPM-Based Linux Platforms
- Installing the 64-Bit JDK on Oracle Linux Platforms
- How to find my current JAVA_HOME in ubuntu?
How to set JAVA_HOME for Java?
You can set your JAVA_HOME in /etc/profile as Petronilla Escarabajo suggests. But the preferred location for JAVA_HOME or any system variable is /etc/environment .
Open /etc/environment in any text editor like nano or gedit and add the following line:
JAVA_HOME="/usr/lib/jvm/open-jdk"
(java path could be different)
Use source to load the variables, by running this command:
Then check the variable, by running this command:
Usually most linux systems source /etc/environment by default. If your system doesn’t do that add the following line to ~/.bashrc (Thanks @pje)
When i tried to run Android Studio (that has IntelliJ IDEA as a base), i had an error message very similar to @advocate’s: «‘tools.jar’ seems to be not in Android Studio classpath.» After fiddling a lot with JAVA_HOME without success, i decided to take a look at studio.sh, the shellscript that starts Android Studio. As a wild guess, i set JDK_HOME to the same value expected for JAVA_HOME, and voila! It installed without great problems.
For those doing software development, don’t put your JAVA_HOME in /etc/environment unless you want to reboot everytime you switch JDK versions.
This is a temporary solution, as others pointed out. No one would want to run source every time they restart their bash.
As others have pointed out, this doesn’t stick between terminal sessions. What I did to address this is just added the line source /etc/environment to the top of my bash config file ~/.bashrc so that it loads all my environment settings on startup. Working for me so far.
Linux jdk home directory
This topic describes the installation procedures of the JDK on the Linux platform, along with the system requirements.
General Notes About Installing the JDK on Linux Platforms from Archive Files
Installing the JDK automatically creates a directory called jdk–feature.interim.update.patch where feature ( 20 ),interim, update, and patch represent corresponding values of version information.
If you install JDK in a specific location such as /opt , you must log in with root credentials to gain the necessary permissions. If you do not have the root access, either install the JDK in your home directory or a sub directory for which you have the write permissions.
If you install the software in a directory that contains a sub directory named jdk– 20 .interim.update.patch , the new software overwrites files of the same name in that directory. Ensure that you rename the old directory if it contains files that you would like to keep.
Installing the JDK from archive files doesn’t configure the backing store for the system node of Java Preferences API ( java.util.prefs Java package). If this functionality of the JDK is required, you need to manually configure it by making sure either /etc/.java/.systemPrefs or jdk– 20 .interim.update.patch/.systemPrefs directory exists.
General Notes About Installing the JDK on Linux Platforms from RPM packages
This topic describes general information about installing JDK 20 from RPM packages on Linux platforms.
You can install only one version of JDK of the same feature release. If you try to install the newer version of the same feature release while the older version exists, the installer uninstalls the older version and installs the new version. For example, you can’t install jdk- 20 and jdk- 20 .0.1 simultaneously. If you attempt to install jdk- 20 .0.1 after jdk- 20 is installed, the installer uninstalls jdk- 20 and installs jdk- 20 .0.1 .
All versions of JDK of the same feature release are installed in /usr/lib/jvm/jdk- 20 -oracle- directory, where equals x64 or aarch64 . Additionally /usr/java/jdk- 20 symbolic link pointing to the installation directory is created for backward compatibility.
If you install an older version of a JDK when the newer version of the same feature family already exists, an error is displayed, prompting you to uninstall a newer JDK version if an older version has to be installed.
You must log in with root credentials to install or update JDK.
By default, the installation script configures the system such that the backing store for the system node of Java Preferences API (java.util.prefs Java package) is configured in /etc/.java/.systemPrefs directory.
The JDK installation is integrated with the alternatives framework. After installation, the alternatives framework is updated to reflect the binaries from the recently installed JDK. Java commands such as java , javac , javadoc , and javap can be called from the command line.
Using the java -version command, you can confirm the default (recently installed) JDK version.
System Requirements for Installing JDK on Linux Platforms
See Oracle JDK Certified Systems Configurations for information about supported platforms, operating systems, and browsers.
Installing the JDK on Linux from Archive Files, RPM Packages and Oracle Linux Repositories
You can install the JDK on a Linux platform from archive files, downloadable Red Hat Package Manager (RPM) packages files, or RPM packages from Oracle Linux (OL) repositories.
Installation can be performed by using one of the following processes:
- From archive files ( .tar.gz ): This allows you to install a private version of the JDK for the current user into any location, without affecting other JDK installations. However, it may involve manual steps to get some of the features to work. See the following table for the options available for downloading and installing the JDK from archive files. The bundles are available for Linux x64 and Linux aarch64 (64-bit ARM) systems. Install the required bundle.
- From downloadable RPM packages ( .rpm ): This allows you to perform a system-wide JDK installation on RPM-based Linux platforms for all users, and requires root access. See the following table for the options available for downloading and installing the JDK from Linux x64 and Linux aarch64 (64-bit ARM) RPM packages.
- From Oracle Linux repositories : This allows you to perform a system-wide JDK installation on OL platforms starting from OL7 for all users, and requires root access. JDK RPM packages in Oracle Linux RPM repositories are available for x64 and aarch64 (64-bit ARM) OL platforms. Explicit download of JDK RPM packages is not required, the package manager will do it automatically for you.
JDK RPM packages for Generic Linux platforms and Oracle Linux platforms differ. The following table lists the differences:
Table 3-1 Difference between Generic Linux and OL platforms
JDK image is split into two packages: jdk- 20 -headless and jdk- 20 -headful .
- jdk- 20 -headless is a headless Java Runtime for running non-GUI applications.
- jdk- 20 -headful is headful Java Runtime and Development Tools for developing and running all types of applications.
jdk- 20 -headful package requires jdk- 20 -headless package. When these packages are installed together, they provide the same functionality as the jdk- 20 package for Generic Linux Platforms.
jdk- 20 -headless package registers java group with the alternatives framework.
jdk- 20 -headful package registers javac group with the alternatives framework.
Downloading the JDK Installer
Access Java SE Downloads page and click Accept License Agreement . Under the Download menu, click the Download link corresponding your requirement.
The following table lists the options and instructions for downloading and installing the JDK 20 release on a Linux platform:
Download File | Instructions | Architecture (CPU Type) | Who Can Install |
---|---|---|---|
For Linux x64 systems: jdk- 20 .interim.update.patch_linux-x64.tar.gz | Installing the 64-Bit JDK on Linux Platforms | Intel — 64-bit | Anyone |
For Linux aarch64 (64-bit ARM) systems: jdk- 20 .interim.update.patch_linux-aarch64.tar.gz | Installing the 64-Bit JDK on Linux Platforms | ARM — 64-bit | Anyone |
For Linux x64 systems: jdk- 20 .interim.update.patch_linux-x64.rpm | Installing the 64-Bit JDK on RPM-Based Linux Platforms | Intel — 64-bit RPM-based Linux | Root |
For Linux aarch64 (64-bit ARM) systems: jdk- 20 .interim.update.patch_linux-aarch64.rpm | Installing the 64-Bit JDK on RPM-Based Linux Platforms | ARM — 64-bit RPM-based Linux | Root |
Installing the 64-Bit JDK on Linux Platforms
You can install the JDK for 64-bit Linux from an archive file ( .tar.gz ). The .tar.gz archive file (also called a tarball) is a file that can be uncompressed and extracted in a single step.
- For Linux x64 systems: jdk- 20 .interim.update.patch_linux-x64_bin.tar.gz . For example jdk- 20 _linux-x64_bin.tar.gz
- For Linux aarch64 (64-bit ARM) systems: jdk- 20 .interim.update.patch_linux-aarch64_bin.tar.gz . For example, jdk- 20 _linux-aarch64_bin.tar.gz
Before you download a file, you must accept the license agreement. Anyone (not only root users) can install the archive file in any location having write access.
Installing the 64-Bit JDK on RPM-Based Linux Platforms
You can install the JDK on 64-bit RPM-based Linux platforms, such as Red Hat and SuSE by using a downloadable RPM package file ( .rpm ) in the system location.
You can install the JDK using a downloadable RPM package file on an OL system too, but the preferred way to install the JDK on OL systems is from Oracle Linux RPM repositories.
Ensure that you have the root user access. You can do this by running the command su and entering the superuser password.
- For x64 systems: jdk- 20 .interim.update.patch_linux-x64_bin.rpm . For example, jdk- 20 _linux-x64_bin.rpm
- For aarch64 (64-bit ARM) systems: jdk- 20 .interim.update.patch_linux-aarch64_bin.rpm . For example, jdk- 20 _linux-aarch64_bin.rpm
Before you download a file, you must accept the license agreement.
Upgrade the required package using the following command: $ sudo rpm -Uvh jdk- 20 _linux-x64_bin.rpm OR $ sudo rpm -Uvh jdk- 20 _linux-aarch64_bin.rpm
Note: JDK 20 can coexist with other feature releases of JDK. For each feature release, a separate directory is created, the default directory being /usr/lib/jvm/jdk-
Installing the 64-Bit JDK on Oracle Linux Platforms
There are two OL-specific JDK RPM packages, jdk- 20 -headless and jdk- 20 -headful . When these packages are installed together, they provide full JDK functionality.
Install jdk- 20 -headless package if you only need headless Java Runtime for running non-GUI applications.
Install jdk- 20 -headful package if you need full JDK functionality for running any Java application and development.
The jdk- 20 -headful package depends on jdk- 20 -headless , hence installing jdk- 20 -headful package will result in the automatic installation of jdk- 20 -headless , if it is not installed yet.
sudo dnf install jdk- 20 -headless
sudo yum install jdk- 20 -headless
sudo dnf install jdk- 20 -headful
sudo yum install jdk- 20 -headful
How to find my current JAVA_HOME in ubuntu?
To display JAVA_HOME variable path, type in terminal:
If nothing appears then set it with this:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
This will differ according to your JDK type and version.
For displaying it again, follow the first command.
Follow JREs from different vendors on the same system, for using different JDK’s or switch between JDK’s.
It gives «/usr/lib/jvm/java-6-sun». But I have installed java 7. When I check it using «java -version» it gives java version «1.7.0_45» Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)
then execute second command for setting JAVA_HOME variable. NOTE: JAVA_HOME doesn’t make jdk default, it just makes JAVA_HOME variable set to a path & if you want to use different jdk installed on same machine then check my answer, I have edited it.
@Jax-L But now when I give echo JAVA_HOME it just displays as «JAVA_HOME». The path I gave is not displaying.
export works only until you restart. Or you add export to the .bashrc login script. But the correct way to set such environment variables is in /etc/environment
If you have JDK 1.6 (corresponding to Java 6) or a newer version installed, you should have a program named jrunscript in your PATH . You can use this to find the corresponding JAVA_HOME . Example:
$ jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));' /opt/local/jdk1.7.0_76/jre
You could set the environment variable like this:
$ export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')"
Note that the JRE doesn’t include jrunscript , so this will only work if you install the JDK, not just the JRE.