Preparing “The Lab”

In the previous discussion, I mentioned about the very first things that I would do after installing LINUX on my PC. Since, I do developments most of the times, the very first thing that comes to my mind is java and a set of some other relevant tools. In this article I would intend to install the following tools on LINUX, which I believe to be very useful for an absolute beginner.
  1. Java, Oracle JDK
  2. Apache Maven
  3. Apache Ant
I would simply keep talking about the steps to be followed to get the things done, rather than explaining every single reason for doing that. After making sure that everything works fine, we may discuss the reasons and rationales, in order to obtain a better understanding.

Installing java.


Download the Oracle JDK

Carefully select the appropriate java version for your OS and the processor architecture.

In my case, I downloaded 'jdk-7u45-linux-x64.tar.gz'―jdk 7, 64 bit tar.gz pack for LINUX.

Let’s assume that your downloads are directed to the default 'Downloads' directory located inside the home directory.

Open the LINUX terminal application and follow the steps mentioned below.

First of all, you need to decide where to install your Java Development Kit. Even if there is not such a specific place to install Java on LINUX, I have seen most of the people install java inside '/usr/lib/jvm' directory as a practice. Therefore, I will also do the same following the same convention.

    cd /usr/lib
[Takes you into the /usr/lib directory]

    mkdir jvm
[Creates a directory called jvm, inside the current location; which is /usr/lib]

    cd jvm
[Takes you into the /usr/lib/jvm directory]

    sudo tar xvzf ~/Downloads/jdk-7u45-linux-x64.tar.gz
[Picks the jdk-7u45-linux-x64.tar.gz archive file from the Downloads directory and extracts it into the current location; which is /usr/lib/jvm]

 Please note a few special things in the last command that we just executed.

sudoInstructs the command (any command) to be executed as the Super User, who has the ultimate permissions on the PC. This will prompt you to enter the Super User (root) password. When you entered the password correctly, it will execute the command.
~/  Is similar to /home/[your user name] . When you type ~/Downloads, it is similar to typing as /home/{your user name}/Downloads.

After that you will see a directory such as ‘jdk1.7.0_45‘ inside the directory /usr/lib/jvm (which is the directory, where now you are. To list and see the contents in that directory, enter the command below.

    ls -l

Now you have finished installing java on your PC. But, in order to use java in future, there is something more to be done. You may simply modify a file which is read and executed like, kind of a start-up script, which would prepare the environment as you wish. For this, you can use your preferred text editor. While LINUX experts use ‘vi editor’ for this. I would instruct you to use ‘gedit’ and get the thing done, since now you are working on your own PC.

    sudo gedit ~/.bashrc

This command will open the ‘.bashrc’ file if exists. If it doesn’t exist it will create a new file called .bashrc in your home directory (~/) and you can save it after the modification. Add these lines to the .bashrc file and save it.


export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45
PATH=$PATH:$JAVA_HOME/bin

When you set and export the JAVA_HOME variable, all the child processes will inherit that and you can easily refer it anywhere as $JAVA_HOME ( Note that it is JAVA_HOME while setting, and $JAVA_HOME while getting ).

In the next line, we have appended the ‘usr/lib/jvm/jdk1.7.0_45/bin’ directory to the existing PATH variable; and there we have used $JAVA_HOME ( which we exported in the earlier line ) to refer the path ‘/usr/lib/jvm/jdk1.7.0_45′. $PATH is the existing path and with ‘colon ( : )’, we append the $JAVA_HOME/bin part to the existing $PATH, and assign it to the PATH again. Now you can save the file and exit. Just type the command below, in order to check whether it has been set properly.

    echo $JAVA_HOME

Surely, you will see nothing but a empty line now; because this $JAVA_HOME variable has not been set yet in the environment. You can either log off and login or, instruct the PC to load what is in the ‘.bashrc’ file into the environment. To do that, use the following command.

    source ~/.bashrc

And execute,

    echo $JAVA_HOME

Now you will observe that /usr/lib/jvm/jdk1.7.0_45 is printed on the console, which indicates that your variables have been properly set.

Installing Apache Maven and Apache Ant


To install Apache MavenApache Ant, I would create a directory called 'build', inside the '/usr/lib', and follow a few similar steps, in order to install both Ant and Maven.


cd /usr/lib
mkdir build
cd build
sudo tar xvzf ~/Downloads/apache-ant-1.9.0-bin.tar.gz
sudo tar xvzf ~/Downloads/apache-maven-3.0.5-bin.tar.gz
sudo gedit ~/.bashrc

When the ~/.bashrc file was opened, append these lines, just like what we did to set the JAVA_HOME,


export ANT_HOME=/usr/lib/build/apache-ant-1.9.0
PATH=$PATH:$ANT_HOME/bin
export M3_HOME=/usr/lib/build/apache-maven-3.0.5
PATH=$PATH:$M3_HOME/bin
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=512m"

Save and exit.


source ~/.bashrc

Now you have successfully finished installing ‘java, ant and Maven’.

Note the last line which we have appended in the .bashrc file [export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=512m" ]. What this line of command does is setting/exporting a variable called MAVEN_OPTS in to all the child processes. Maven will be using this to increase the memory that it is allowed to consume.

Now your PC is ready for Java based developments, and additionally you can use either Apache Ant or Apache Maven to get those built.

When we talk in brief about the writing style I chose for do Blogging―I try compose everything having assumed that an absolute beginner would visit this Blog always, rather than the experts. Therefore, I thought to keep things simple; mention what to do first and make sure that it works fine; and then walk you through the matters in detail and let the reasons and the rationale to be understood.

Comments