How To Install Java On Xubuntu
The author selected the Open Internet/Gratis Speech Fund to receive a $100 donation every bit part of the Write for DOnations program.
Introduction
Java and the JVM (Java'south virtual machine) are required for many kinds of software, including Tomcat, Jetty, Glassfish, Cassandra and Jenkins.
In this guide, you volition install various versions of the Java Runtime Surroundings (JRE) and the Java Developer Kit (JDK) using apt. You'll install OpenJDK as well every bit the official JDK from Oracle. You'll then select the version y'all wish to utilize for your projects. When you're finished, you'll be able to use the JDK to develop software or use the Java Runtime to run software.
Prerequisites
To follow this tutorial, y'all volition need:
- One Ubuntu eighteen.04 server set up past post-obit the the Ubuntu 18.04 initial server setup guide tutorial, including a sudo non-root user and a firewall.
Installing the Default JRE/JDK
The easiest pick for installing Coffee is to employ the version packaged with Ubuntu. By default, Ubuntu xviii.04 includes Open JDK 11, which is an open-source variant of the JRE and JDK.
To install this version, first update the bundle index:
- sudo apt update
Next, bank check if Java is already installed:
- java -version
If Java is not currently installed, you'll see the following output:
Output
Command 'java' not found, but can be installed with: sudo apt install default-jre sudo apt install openjdk-eleven-jre-headless sudo apt install openjdk-eight-jre-headless Execute the following command to install the default Java Runtime Environs (JRE), which will install the JRE from OpenJDK 11:
- sudo apt install default-jre
The JRE will let you to run virtually all Java software.
Verify the installation with:
- coffee -version
You'll meet output like to the following:
Output
openjdk version "11.0.11" 2022-04-twenty OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.xviii.04) OpenJDK 64-Bit Server VM (build 11.0.11+ix-Ubuntu-0ubuntu2.18.04, mixed way, sharing)) You may need the Java Evolution Kit (JDK) in addition to the JRE in social club to compile and run some specific Java-based software. To install the JDK, execute the following command, which will also install the JRE:
- sudo apt install default-jdk
Verify that the JDK is installed past checking the version of javac, the Java compiler:
- javac -version
You'll see the following output:
Output
javac 11.0.11 Next, permit's await at how to install Oracle's official JDK and JRE.
Installing Oracle JDK 11
Oracle'due south licensing agreement for Java doesn't allow automated installation through package managers. To install the Oracle JDK, which is the official version distributed by Oracle, you must create an Oracle account and manually download the JDK to add together a new package repository for the version you'd like to use. Then you tin use apt to install it with help from a third party installation script.
The version of Oracle's JDK yous'll need to download must match version of the installer script. To find out which version you lot demand, visit the oracle-java11-installer page.
Locate the package for Bionic, as shown in the following effigy:
In this prototype, the version of the script is 11.0.7. In this case, you'll need Oracle JDK 11.0.7. You don't need to download annihilation from this page; y'all'll download the installation script through apt before long.
So visit the Downloads folio and locate the version that matches the 1 y'all need.
Click the JDK Download button and you'll be taken to a screen that shows the versions available. Click the .tar.gz package for Linux.
You'll be presented with a screen request you to accept the Oracle license agreement. Select the checkbox to accept the license agreement and press the Download push. Your download will begin. You may need to log in to your Oracle account i more fourth dimension before the download starts.
One time the file has downloaded, y'all'll need to transfer it to your server. On your local automobile, upload the file to your server. On macOS, Linux, or Windows using the Windows Subsystem for Linux, utilise the scp command to transfer the file to the home directory of your sammy user. The following control assumes y'all've saved the Oracle JDK file to your local machine'due south Downloads folder:
- scp Downloads/jdk-eleven.0.7_linux-x64_bin.tar.gz sammy@your_server_ip:~
Once the file upload has completed, return to your server and add the third-political party repository that will assistance you install Oracle'southward Coffee.
Install the software-properties-common package, which adds the add-apt-repository command to your organisation:
- sudo apt install software-properties-common
Adjacent, import the signing key used to verify the software you're near to install:
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EA8CACC073C3DB2A
You'll see this output:
Output
gpg: key EA8CACC073C3DB2A: public primal "Launchpad PPA for Linux Uprising" imported gpg: Total number processed: one gpg: imported: ane So utilize the add-apt-repository control to add together the repo to your listing of package sources:
- sudo add-apt-repository ppa:linuxuprising/java
You'll see this bulletin:
Output
Oracle Java 11 (LTS) and 12 installer for Ubuntu, Linux Mint and Debian. Java binaries are non hosted in this PPA due to licensing. The packages in this PPA download and install Oracle Java 11, and so a working Internet connection is required. The packages in this PPA are based on the WebUpd8 Oracle Coffee PPA packages: https://launchpad.cyberspace/~webupd8team/+archive/ubuntu/java Created for users of https://world wide web.linuxuprising.com/ Installation instructions (with some tips), feedback, suggestions, bug reports etc.: . . . Press [ENTER] to go on or ctrl-c to cancel adding information technology Printing ENTER to go along the installation. You lot may run into a message well-nigh no valid OpenPGP data found, simply you tin can safely ignore this.
Update your bundle list to make the new software available for installation:
- sudo apt update
The installer volition look for the Oracle JDK you downloaded in /var/cache/oracle-jdk11-installer-local. Create this directory and move the Oracle JDK archive there:
- sudo mkdir -p /var/cache/oracle-jdk11-installer-local/
- sudo cp jdk-11.0.7_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/
Finally, install the package:
- sudo apt install oracle-java11-installer-local
The installer will first enquire you to accept the Oracle license agreement. Accept the understanding, then the installer will extract the Java packet and install information technology.
Now permit's look at how to select which version of Java you desire to use.
Managing Java
Y'all tin can accept multiple Java installations on one server. You lot can configure which version is the default for utilize on the command line by using the update-alternatives command.
- sudo update-alternatives --config java
This is what the output would look similar if you've installed both versions of Coffee in this tutorial:
Output
At that place are 2 choices for the culling java (providing /usr/bin/java). Selection Path Priority Condition ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 automobile mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 transmission mode * 2 /usr/lib/jvm/java-11-oracle/bin/java 1091 manual mode Press <enter> to continue the electric current choice[*], or type selection number: Cull the number associated with the Java version to use it as the default, or press ENTER to get out the current settings in place.
You can practise this for other Java commands, such as the compiler (javac):
- sudo update-alternatives --config javac
Other commands for which this command tin exist run include, but are non express to: keytool, javadoc and jarsigner.
Setting the JAVA_HOME Environment Variable
Many programs written using Java utilise the JAVA_HOME surround variable to make up one's mind the Java installation location.
To set this surroundings variable, first make up one's mind where Java is installed. Use the update-alternatives command:
- sudo update-alternatives --config coffee
This command shows each installation of Java forth with its installation path:
Output
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/coffee-eleven-openjdk-amd64/bin/java 1111 auto mode i /usr/lib/jvm/java-xi-openjdk-amd64/bin/java 1111 manual fashion * ii /usr/lib/jvm/coffee-11-oracle/bin/java 1091 manual style Printing <enter> to go along the current pick[*], or type option number: In this case the installation paths are equally follows:
- OpenJDK eleven is located at
/usr/lib/jvm/coffee-11-openjdk-amd64/bin/coffee. - Oracle Coffee is located at
/usr/lib/jvm/java-11-oracle/jre/bin/java.
Copy the path from your preferred installation. And then open up /etc/environment using nano or your favorite text editor:
- sudo nano /etc/surroundings
At the terminate of this file, add the following line, making sure to supervene upon the highlighted path with your own copied path, but practice not include the bin/ portion of the path:
/etc/environment
JAVA_HOME="/usr/lib/jvm/coffee-11-openjdk-amd64" Modifying this file volition set up the JAVA_HOME path for all users on your organization.
Salvage the file and exit the editor.
At present reload this file to apply the changes to your current session:
- source /etc/environment
Verify that the environment variable is set:
- echo $JAVA_HOME
You'll see the path you lot just set:
Output
/usr/lib/jvm/java-11-openjdk-amd64 Other users will demand to execute the command source /etc/environment or log out and log back in to apply this setting.
Conclusion
In this tutorial you installed multiple versions of Java and learned how to manage them. You can now install software which runs on Java, such as Tomcat, Jetty, Glassfish, Cassandra or Jenkins.
Source: https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-on-ubuntu-18-04
Posted by: gandhioundiciat.blogspot.com

0 Response to "How To Install Java On Xubuntu"
Post a Comment