Install java on ubuntu

In this tutorial we will learn how to install java and setup required java variables on ubuntu.

Java is one of the famous programming languages which allow developers to compile programs once and then run anywhere.

In this tutorials commands are provided to install java on ubuntu 16.04.

Installing java using default packages.

First of all we will update all existing packages on OS to latest version.

apt-get update && apt-get upgrade

Once OS’s packages updated install latest version of Java Runtime Environment (JRE) by executing following command:

apt-get install default-jre

You can install jdk instead of jre which is required to compile java programs. JDK is recommended as it includes jre as well.

apt-get install default-jdk

That’s all java is ready to use.

java -version
javac -version

Now setting up java installation path as JAVA_HOME variable. To find location execute command

update-alternatives --config java

Once you get path set it as JAVA_HOME by adding it to file /etc/environment like

JAVA_HOME="/usr/lib/jvm/java-9-oracle/bin/java"

To activate this variable for current session execute following command

JAVA_HOME="/usr/lib/jvm/java-9-oracle/bin/java"

Verify it is activated by executing command

echo $JAVA_HOME

That’s it.

How to add files folders to an existing TAR archive

It is possible to append on existing TAR archive.

We can add additional files/folders to an already existing TAR archive.

For example:

Create 3 files named as file1 file2 file3

[root@linux midnight]# touch file1 file2 file3

List file created.

[root@linux midnight]# ls -l
total 0
-rw-r--r-- 1 root root 0 Oct 29 10:26 file1
-rw-r--r-- 1 root root 0 Oct 29 10:26 file2
-rw-r--r-- 1 root root 0 Oct 29 10:26 file3

Create tar archive named as file.tar using following command

[root@linux midnight]# tar -cvf file.tar file1 file2 file3
file1
file2
file3

List contains of tar file file.tar

[root@linux midnight]# tar -tf file.tar
file1
file2
file3

Create additional file

[root@linux midnight]# touch file4

Add file4 to existing file.tar

[root@linux midnight]# tar -rf file.tar file4

List files of file.tar and see 4th file is added.

[root@linux midnight]# tar -tf file.tar
file1
file2
file3
file4

 

Systemctl to disable service on boot

We will learn basic commands to manage systemd services and units using systemctl.

Using systemctl we can enable disable particular service to be started or stopped when system boot.

To check status of service use

systemctl status postfix.service

To stop service use

systemctl stop postfix.service

To start service

systemctl start postfix.service

To disable the service from starting automatically on boot, type:

systemctl stop postfix.service

and then

systemctl disable postfix.service

This will make sure service is stopped now and will not start automatically after server reboot.

If you want service should be started automatically when server boot you will need to enable it using following command.

systemctl enable postfix.service