Installing the Default JRE/JDK
First, update the package index.
$ sudo apt-get update
Next, install Java. Specifically, this command will install the Java Runtime Environment (JRE).
$ sudo apt-get install default-jre
There is another default Java installation called the JDK (Java Development Kit). The JDK is usually only needed if you are going to compile Java programs or if the software that will use Java specifically requires it. The JDK does contain the JRE, so there are no disadvantages if you install the JDK instead of the JRE, except for the larger file size. You can install the JDK with the following command:
$ sudo apt-get install default-jdk
Installing the Oracle JDK
First, add Oracle's PPA, then update your package repository.
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:
$ sudo apt-get install oracle-java6-installer
$ sudo apt-get install oracle-java7-installer
$ sudo apt-get install oracle-java8-installer
Configure which version is the default for use in the command line by using update-alternatives, which manages which symbolic links are used for different commands.
$ sudo update-alternatives --config java
Setting the JAVA_HOME Environment Variable
Many programs, such as Java servers, use the JAVA_HOME environment variable to determine the Java installation location. To set this environment variable, we will first need to find out where Java is installed. You can do this by executing the same command as in the previous section:
$ sudo update-alternatives --config java
Copy the path from your preferred installation and then open /etc/environment using nano or your favorite text editor.
$ sudo nano /etc/environment
At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path /etc/environment
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
Save and exit the file, and reload it.
$ source /etc/environment
You can now test whether the environment variable has been set by executing the following command:
$ echo $JAVA_HOME
This will return the path you just set.
First, update the package index.
$ sudo apt-get update
Next, install Java. Specifically, this command will install the Java Runtime Environment (JRE).
$ sudo apt-get install default-jre
There is another default Java installation called the JDK (Java Development Kit). The JDK is usually only needed if you are going to compile Java programs or if the software that will use Java specifically requires it. The JDK does contain the JRE, so there are no disadvantages if you install the JDK instead of the JRE, except for the larger file size. You can install the JDK with the following command:
$ sudo apt-get install default-jdk
Installing the Oracle JDK
First, add Oracle's PPA, then update your package repository.
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:
$ sudo apt-get install oracle-java6-installer
$ sudo apt-get install oracle-java7-installer
$ sudo apt-get install oracle-java8-installer
Configure which version is the default for use in the command line by using update-alternatives, which manages which symbolic links are used for different commands.
$ sudo update-alternatives --config java
Setting the JAVA_HOME Environment Variable
Many programs, such as Java servers, use the JAVA_HOME environment variable to determine the Java installation location. To set this environment variable, we will first need to find out where Java is installed. You can do this by executing the same command as in the previous section:
$ sudo update-alternatives --config java
Copy the path from your preferred installation and then open /etc/environment using nano or your favorite text editor.
$ sudo nano /etc/environment
At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path /etc/environment
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
Save and exit the file, and reload it.
$ source /etc/environment
You can now test whether the environment variable has been set by executing the following command:
$ echo $JAVA_HOME
This will return the path you just set.
Comments
Post a Comment