Installing Java, Git and Maven on Ubuntu

  • Java 

Java and the JVM (Java’s virtual machine) are widely used and required for many kinds of software. This article will guide you through the process of installing and managing different versions of Java using apt-get.

The easiest option for installing Java is using the version packaged with Ubuntu. Specifically, this will install OpenJDK 8, the latest and recommended version.

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

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 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.

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"

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

 

  • Git 

The easiest way of getting git installed and ready to use is by using Ubuntu’s default repositories. This is the fastest method, but the version may be older than the newest version. If you need the latest release, consider following the steps to compile git from source.

You can use the apt package management tools to update your local package index. Then, you can download and install the program:

sudo apt-get update

sudo apt-get install git

This will download and install  git to your system. You will still have to complete the configuration steps as below –

git config --global user.name "<span class="highlight">Your Name</span>"

git config --global user.email "<span class="highlight">[email protected]</span>"

We can see all of the configuration items that have been set by typing:

git config --list

  • Maven

The maven package always comes with latest Apache Maven.You can download and install maven using below commands:

sudo apt-get update

sudo apt-get install maven

Run command mvn –version to verify your installation.

Leave a Comment

Bitnami