I know lot of you starting out new as Linux users or Java learners on Linux platform find it an issue to install JDK or may be configure it to start using after installing. At time the version of java that comes with the package manager (apt-get for Ubuntu) would be an older version and you would require you to download the compressed binaries. In any case I have outlined how to configure in both the cases.
Case: 1- You would have to download the required JDK binary package from here. And follow the Steps for Case-1 below. This would involve extracting the compressed binary and then setting up the $PATH.
Case: 2- You have installed the JDK package using the apt-get and it installs JDK to some location (I haven’t used this approach because when ever I tried I ended up with an older version of JDK, so I have not explained it in detail).
Also note that usually the Linux installation might come with the OpenJDK but I have never used that before.
Steps for Case-1
Suppose you happen to download the JDK from the Oracle Downloads site here, then you can follow the below procedure:
1. Download the required Java SE package from the Oracle Download site here. [Download the compressed Binary and Preferably Java SE 7]
2. Extract it in to a location of you choice- I used the /home/jdk<version>
3. Update the $PATH variable to locate the jdk/bin directory so that the shell can recognize the java and javac commands. This can be done by appending the PATH variable with the location to the jdk bin. In bash you can either use a seperate alias file- .bash_aliases and refer it in the .bashrc file or directly add in the .bashrc file. Here I am using a seperate alias file: .bash_aliases - In this file u can specify the variable values- for PATH, CLASSPATH and others required ones and also aliases for you various commands.
There’s a catch here: If you just initialize the $PATH variable with the jdk bin location then you will loose out the access to other bin dirs like- /usr/bin, /bin, /usr/local/bin and so on. Instead you would have to update/append the $PATH variable.
Lets assume you extracted the JDK compressed binary to- /home/jdk1.6.0_16
(Note: the dir- jdk1.6.0_16 naming would differ based on the version of JDK you have downloaded)
So the .bash_aliases file would look something like this
JAVA_HOME=/home/usr/jdk1.6.0_16 export JAVA_HOME PATH=$PATH:$JAVA_HOME/bin: export PATH CLASSPATH=$JAVA_HOME/lib/:. export CLASSPATH
The ‘:‘ is the separator, for windows it would be “;“. Its optional to update the CLASSPATH as one can provide it during the execution of Java program or if you are using an IDE it will manage the CLASSPATH or for that matter if you are using an tools like Ant, Maven. So just in case you are used to providing the CLASSPATH and may be use command line at times for you demo programs here’s a small tip:
Note that in the CLASSPATH- there’s an addition value “.“. This points to the current directory and will be helpful when the class files are in the current directory. Otherwise java will search for the classes in the directories mentioned in the CLASSPATH and will return ClassNotFoundException if the current directory is not part of the CLASSPATH and the required class files are in the current directory. Other option is to use -cp and specify the classpath. In that case the value of the CLASSPATH variable is overridden with the value specified by -cp.
Steps for Case-2
Suppose you have use the apt-get command to install the JDK, the you can follow the below procedure and this has to be done every time you enter the terminal or best is to put it in a .bashrc or .bash_aliases file as mentioned above:
JAVA_HOME=/usr/lib/jvm/java export JAVA_HOME PATH=$PATH:$JAVA_HOME/bin export PATH
No related posts.
Connect to us …
- May 2013 (8)
- April 2013 (6)
- March 2013 (6)
- January 2013 (5)
- November 2012 (2)
- September 2012 (1)
- July 2012 (5)
- June 2012 (1)
- May 2012 (4)
- April 2012 (7)
- March 2012 (2)
- February 2012 (4)
- December 2011 (2)
- November 2011 (4)
- October 2011 (2)
- September 2011 (1)
- August 2011 (1)
- July 2011 (1)
- June 2011 (1)
- May 2011 (1)
- April 2011 (1)
- February 2011 (4)
- December 2010 (3)
- November 2010 (2)
- September 2010 (2)
- August 2010 (3)
- May 2010 (2)
- March 2010 (6)
- December 2009 (1)
- November 2009 (3)
- July 2009 (6)
- June 2009 (3)
- May 2009 (1)
- April 2009 (6)
- March 2009 (1)
- January 2009 (1)
- December 2008 (8)
- November 2008 (5)
- October 2008 (6)
- September 2008 (4)
- August 2008 (8)
- July 2008 (19)
- June 2008 (29)
- May 2008 (27)
- April 2008 (11)
- March 2008 (8)
- February 2008 (22)
- January 2008 (3)
Send To ReadmillSend to Readmill
- How to create ADF TreeTable programmatically?
- Book review: The Object-Oriented Thought Process
- How to show links in ADF Messages
- Runtime Polymorphism in Java
- Understanding RowKey values in ADF TreeTable
- Train Wreck Pattern – A much improved implementation in Java 8
- Converting a List into comma separated value string in Java
- A simple application of Lambda Expressions in Java 8
- Template Method Pattern- Using Lambda Expressions, Default Methods
- First look at Learning Play! Framework 2
Some of the links contained within this site have my referral id, which provides me with a small commission for each sale. Thank you for your support.