Vous êtes sur la page 1sur 20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Tutorials BASH Shell Troubleshooting Nginx Networking MySQL Google Cloud Platform Amazon Cloud Computing Rackspace Cloud Computing Linux CentOS Debian / Ubuntu Ubuntu Linux Suse RedHat and Friends Slackware Linux UNIX AIX Mac OS X FreeBSD FreeBSD Jails (VPS) Openbsd Solaris See all tutorial topics Blog About Contact us Forum Linux Scripting Guide RSS/FEED

Linux FAQ / Howtos

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile


by Nix Craft on October 10, 2007 74 comments LAST UPDATED May 25, 2012 in BASH Shell, CentOS, Debian / Ubuntu I just need a help to show me how to setup java path on Linux. How can I set JAVA_HOME and PATH variables for every user under my Linux system? ~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to set environment variables such as PATH, JAVA_HOME, to create aliases for shell commands, and to set the default permissions for newly created files.

Set JAVA_HOME / PATH for a single user


http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 1/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Login to your account and open .bash_profile file


$v i~ / . b a s h _ p r o f i l e

Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
e x p o r tJ A V A _ H O M E = / u s r / j a v a / j d k 1 . 5 . 0 _ 0 7 / b i n / j a v a

Set PATH as follows:


e x p o r tP A T H = $ P A T H : / u s r / j a v a / j d k 1 . 5 . 0 _ 0 7 / b i n

Feel free to replace /usr/java/jdk1.5.0_07 as per your setup. Save and close the file. Just logout and login back to see new changes. Alternatively, type the following command to activate the new path settings immediately:
$s o u r c e~ / . b a s h _ p r o f i l e

OR
$.~ / . b a s h _ p r o f i l e

Verify new settings:


$e c h o$ J A V A _ H O M E $e c h o$ P A T H

Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
$w h i c hj a v a

Please note that the file ~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.

Set JAVA_HOME / PATH for all user


You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
#v i/ e t c / p r o f i l e

Next setup PATH / JAVA_PATH variables as follows:


e x p o r tP A T H = $ P A T H : / u s r / j a v a / j d k 1 . 5 . 0 _ 0 7 / b i n e x p o r tP A T H = $ P A T H : / u s r / j a v a / j d k 1 . 5 . 0 _ 0 7 / b i n

Save and close the file. Once again you need to type the following command to activate the path settings immediately:
#s o u r c e/ e t c / p r o f i l e

OR
#./ e t c / p r o f i l e

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us! Featured Articles: 30 Cool Open Source Software I Discovered in 2013 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X Top 30 Nmap Command Examples For Sys/Network Admins 25 PHP Security Best Practices For Sys Admins 20 Linux System Monitoring Tools Every SysAdmin Should Know 20 Linux Server Hardening Security Tips Linux: 20 Iptables Examples For New SysAdmins Top 20 OpenSSH Server Best Security Practices Top 20 Nginx WebServer Best Security Practices 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors 15 Greatest Open Source Terminal Applications Of 2012 My 10 UNIX Command Line Mistakes Top 10 Open Source Web-Based Project Management Software Top 5 Email Client For Linux, Mac OS X, and Windows Users The Novice Guide To Buying A Linux Laptop { 74 comments read them below or add one } 1 dino November 13, 2007 at 5:23 am
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 2/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

I believe this is wrong ! 1) In my case I did all you said for .bash_profile, however, running which java still shows old java path (crappy java that comes with linux fedora 7) 2) I tried the same to set /etc/profile but I believe you provided wrong sintax Could somebody provide correct sintax for seting java path in /etc/profile or whatever as long as my which java will show my newest java? Thanks Reply 2 Bijudas Porathur March 19, 2012 at 1:54 pm The correct syntax is as show below, export PATH=/usr/java/jdk1.7.0_03/bin:$PATH Reply 3 Mustafa Buljubasic November 13, 2007 at 5:44 am I have read lots of user posting at various pages and none of them would work. Finally, I found a way to do this correctly and hope this will help to some of you. Follow the simple steps: 1. To set the environment variables : echo export JAVA_HOME=/opt/jdk1.5.0_12 > /etc/profile.d/jdk.sh echo export PATH=$JAVA_HOME/bin:$PATH >> /etc/profile.d/jdk.sh 2. You have to source the file you just created by typing: source /etc/profile.d/jdk.sh 3. Test if Java environment is successfully installed by typing in this in the shell: java -version Reply 4 NAVEEN SHARMA December 15, 2010 at 4:21 pm when I type these above script or command my terminal say Permission denied. Tell the answer Thanks in Advnace Reply 5 Chandrasekar February 16, 2011 at 6:57 am use sudo if youre using ubuntu. else try using su Try googling in case both dont work :D Reply 6 Sreenivasa Reddy Mulinti March 23, 2014 at 5:03 am

http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

3/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Hi Mustafa, Thank you for solution. This worked perfectly for me in Linux. Reply 7 Mustafa Buljubasic November 13, 2007 at 6:03 am I have read lots of posting and none of them worked well. This one did so I decided to try to post it hopefully somebody else wont have to get this frustrated to get such a simple thing done. 1. To set the environment variables: echo export JAVA_HOME=/opt/jdk1.5.0_12 > /etc/profile.d/jdk.sh echo export PATH=$JAVA_HOME/bin:$PATH >> /etc/profile.d/jdk.sh 2. You have to source the file you just created by typing: source /etc/profile.d/jdk.sh 3. Test if Java environment is successfully installed by typing in this in the shell: $ java -version java version 1.6.0_03 Java(TM) SE Runtime Environment (build 1.6.0_03-b05) Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode) You can also use which java to test: $ which java /usr/java/jdk1.6.0_03/bin/java Reply 8 sandeep February 2, 2011 at 8:59 am hay it is workingbut how can i set permentally setthe java path its working only one terminoal only i need permentally java path setting help me Reply 9 ashwin February 25, 2011 at 8:09 am Hi Sandeep, Setting java class path in Linux: I have faced the same problem . How to set it permanently. please help me Reply 10 csr June 3, 2011 at 7:15 am +1 Made my day. Thank you. Reply 11 Mustafa Buljubasic November 13, 2007 at 6:11 am my last reply is using mistakenly 2 different versions of jdk. Reference to jdk in point 1 and 3 should be the same as well as in the testing part
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 4/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Reply 12 Mustafa Buljubasic November 13, 2007 at 6:16 am My last 2 postings use 2 different jdk by accident. References to jdk should be the same. For the sake of consistance, please use (of course substitute your java directory in place of mine /usr/lib/java/jdk.): echo export JAVA_HOME=/usr/lib/java/jdk1.6.0_03 > /etc/profile.d/jdk.sh istead of echo export JAVA_HOME=/opt/jdk1.5.0_12 > /etc/profile.d/jdk.sh My appologies. Reply 13 CamNhung September 27, 2010 at 4:06 am at the terminal. You type 2 comand to apply the env for bath shell. #source /etc/profile #/etc/init.d/x11-common restart Reply 14 Ado January 29, 2008 at 9:21 am Mustafa-pasa, bas se nesto gnjavim sa serverom ali ovaj tvoj post je dosao ko kec na desetku. Thanks for your post, it does exactly what it says on the tin. Just what I needed. Reply 15 mohammed February 18, 2008 at 12:35 am I use the IDE 6 with netbeans to create a simple application and I build it and when I navigate to its dist location through the terminal and type: >> java -jar addition.jar it gives me this message could you please help me to solve this problem: Exception in thread main java.lang.NoClassDefFoundError: javax/swing/GroupLayout$Group Reply 16 ash April 24, 2008 at 10:34 am i need to run my application with jdk,jmf and jakarta tomcat hw do i go about setting the environment variables? Reply 17 rupert June 13, 2008 at 10:39 pm I think its worth mentioning that on most Linux systems, there is a convenient facility to manage different java implementations its called alternatives depending on the version of your system it may be: /usr/sbin/alternatives config java or sudo update-alternatives config java Reply
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 5/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

18 rupert June 14, 2008 at 12:25 am Rather than log out and back in you can run your new bash profile with a single period: $ cd $ . .bash_profile Reply 19 Mustafa Buljubasic December 14, 2008 at 7:49 pm How to install JDK (Java Development Kit) on Linux, In my case Fedora 10? 1. Log in as root: sutype in your password and the prompt will change from $: to #: 2. Download JDK from here: http://java.sun.com/javase/downloads/index.jsp As of time of this post, the most current JDK was: Java SE Development Kit (JDK) 6 Update 11. Select file jdk-6u11-linux-i586.rpm.bin to download it by providing your operation system and multilanguage. 3. Go to directory where you downloaded the file (In my case it is Download directory in /home/username/Download/) The file is called jdk-6u11-linux-i586.rpm.bin 4. Change mode of this file so you can execute it by issuing:
c h m o d7 5 5j d k 6 u 1 1 l i n u x i 5 8 6 . r p m . b i n

5. run the file by issuing:


. / j d k 6 u 1 1 l i n u x i 5 8 6 . r p m . b i n

This will show acceptance agreement, press untill you reach end they type yes and press and the installation will start. 6. When installation completes, you will need to find the actuall location of your JDK and make Fedora accept your choice. You can do this by issuing: updatedb;locate javac |grep bin This will list several options (at least two, the default one shipped with fedora, and the one you downloaded from Java Sun in step 2 above. In my case, I get: [root@DRACHE Download]# locate javac |grep bin /usr/bin/javac /usr/java/jdk1.6.0_10/bin/javac /usr/java/jdk1.6.0_11/bin/javac this is what we downloaded in step 2 above, we want to make make Fedora recognaze this jdk. 7. To make Fedora recognaze your jdk (JVM), use alternatives command and issue following 3 commands one after another:
a l t e r n a t i v e si n s t a l l/ u s r / b i n / j a v aj a v a/ u s r / j a v a / j d k 1 . 6 . 0 _ 1 1 / b i n / j a v a1 0 0 a l t e r n a t i v e si n s t a l l/ u s r / b i n / j a rj a r/ u s r / j a v a / j d k 1 . 6 . 0 _ 1 1 / b i n / j a r1 0 0 a l t e r n a t i v e si n s t a l l/ u s r / b i n / j a v a cj a v a c/ u s r / j a v a / j d k 1 . 6 . 0 _ 1 1 / b i n / j a v a c1 0 0

These 3 commands set your java, jar and javac commands. You can use same to set other java executables if you want. 8. Configure alternatives to use the jdk you downloaded above in step 2 rather than the java shipped with Fedora by issuing:
/ u s r / s b i n / a l t e r n a t i v e sc o n f i gj a v a

This will present you with at least 2 options (one is the default jdk shipped with Fedora, other is jdk you downloaded in step 2 above). In my case, I have somehting like this but in your case, this can look different:
/ u s r / s b i n / a l t e r n a t i v e sc o n f i gj a v a

There are 6 programs which provide java.


http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 6/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

S e l e c t i o n C o m m a n d 1 / u s r / l i b / j v m / j r e 1 . 6 . 0 o p e n j d k . x 8 6 _ 6 4 / b i n / j a v a 2 / u s r / l i b / j v m / j r e 1 . 5 . 0 g c j / b i n / j a v a * 3 / u s r / j a v a / d e f a u l t / b i n / j a v a +4 / u s r / j a v a / j d k 1 . 6 . 0 _ 1 1 / b i n / j a v a 5 / u s r / j a v a / j d k 1 . 6 . 0 _ 1 1 / b i n / j a r 6 / u s r / j a v a / j d k 1 . 6 . 0 _ 1 1 / b i n / j a v a c

Enter to keep the current selection[+], or type selection number: 9. Choose the one you downloaded in step 2 above and press . In my case, that is option 4. 10. repeat the same for jar and javac command as:
/ u s r / s b i n / a l t e r n a t i v e sc o n f i gj a r / u s r / s b i n / a l t e r n a t i v e sc o n f i gj a v a c

11. Issue:
j a v av e r s i o n

and you will see something like this: [dino@DRACHE Download]$ java -version java version 1.6.0_11 Java(TM) SE Runtime Environment (build 1.6.0_11-b03) Java HotSpot(TM) Server VM (build 11.0-b16, mixed mode) Now you are done. Hope this helps :) Mustafa Buljubasic Thanks to article from Angsuman Chakraborty from August 7th, 2007 Useful links on how to install JDK, Adobe Flash Player, MP3 players, Media Players, Java Runtime, and much more : http://blog.taragana.com/index.php/archive/how-to-install-jdk-6-java-se-6-tomcat-in-fedora-core-6-fedora-7-in-5-minutes/ http://www.mjmwired.net/resources/mjm-fedora-f10.html#java Reply 20 zirimu andrew austin June 6, 2011 at 11:19 am Thanks Mustafa, It worked like a charm for me , am using RHEL5 Reply 21 kieron August 23, 2011 at 4:41 am Thanks, this helped me. Fedora 14 Reply 22 Daniel Hannuschka November 12, 2011 at 12:13 am Hey Mustafa, it works very well but my command was another on ubuntu 11! I had to use :
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 7/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile


d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $s u d ou p d a t e a l t e r n a t i v e s c o n f i gj a v a E sg i b tn u re i n eA l t e r n a t i v ei nL i n k G r u p p ej a v a :/ u s r / l i b / j v m / j a v a 6 o p e n j d k / j r e / b i n / j a v a N i c h t sz uk o n f i g u r i e r e n . d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $s u d ou p d a t e a l t e r n a t i v e si n s t a l l/ u s r / b i n / j a v aj a v a/ h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a v a1 0 0 d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $s u d ou p d a t e a l t e r n a t i v e si n s t a l l/ u s r / b i n / j a rj a r/ h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a r1 0 0 d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $s u d ou p d a t e a l t e r n a t i v e si n s t a l l/ u s r / b i n / j a v a cj a v a c/ h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a v a c1 0 0 d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $s u d ou p d a t e a l t e r n a t i v e s c o n f i gj a v a E sg i b t2A u s w a h l m g l i c h k e i t e nf rd i eA l t e r n a t i v ej a v a( w e l c h e/ u s r / b i n / j a v ab e r e i t s t e l l e n ) . A u s w a h l P f a d P r i o r i t tS t a t u s *0 / u s r / l i b / j v m / j a v a 6 o p e n j d k / j r e / b i n / j a v a 1 0 6 1 A u t o M o d u s 1 / h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a v a 1 0 0 m a n u e l l e rM o d u s 2 / u s r / l i b / j v m / j a v a 6 o p e n j d k / j r e / b i n / j a v a 1 0 6 1 m a n u e l l e rM o d u s D r c k e nS i ed i eE i n g a b e t a s t e ,u md i ea k t u e l l eW a h l [ * ]b e i z u b e h a l t e n , o d e rg e b e nS i ed i eA u s w a h l n u m m e re i n :1 u p d a t e a l t e r n a t i v e s :/ h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a v aw i r dv e r w e n d e t ,u m/ u s r / b i n / j a v a( j a v a )i mm a n u e l l e rM o d u sb e r e i t z u s t e l l e n . d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $s u d ou p d a t e a l t e r n a t i v e s c o n f i gj a r E sg i b t3A u s w a h l m g l i c h k e i t e nf rd i eA l t e r n a t i v ej a r( w e l c h e/ u s r / b i n / j a rb e r e i t s t e l l e n ) . A u s w a h l P f a d P r i o r i t tS t a t u s *0 / u s r / l i b / j v m / j a v a 6 o p e n j d k / b i n / j a r 1 0 6 1 A u t o M o d u s 1 / h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a r 1 0 0 m a n u e l l e rM o d u s 2 / u s r / b i n / f a s t j a r 1 0 0 m a n u e l l e rM o d u s 3 / u s r / l i b / j v m / j a v a 6 o p e n j d k / b i n / j a r 1 0 6 1 m a n u e l l e rM o d u s D r c k e nS i ed i eE i n g a b e t a s t e ,u md i ea k t u e l l eW a h l [ * ]b e i z u b e h a l t e n , o d e rg e b e nS i ed i eA u s w a h l n u m m e re i n :1 u p d a t e a l t e r n a t i v e s :/ h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a rw i r dv e r w e n d e t ,u m/ u s r / b i n / j a r( j a r )i mm a n u e l l e rM o d u sb e r e i t z u s t e l l e n . d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $s u d ou p d a t e a l t e r n a t i v e s c o n f i gj a v a c E sg i b t2A u s w a h l m g l i c h k e i t e nf rd i eA l t e r n a t i v ej a v a c( w e l c h e/ u s r / b i n / j a v a cb e r e i t s t e l l e n ) . A u s w a h l P f a d P r i o r i t tS t a t u s *0 / u s r / l i b / j v m / j a v a 6 o p e n j d k / b i n / j a v a c 1 0 6 1 A u t o M o d u s 1 / h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a v a c 1 0 0 m a n u e l l e rM o d u s 2 / u s r / l i b / j v m / j a v a 6 o p e n j d k / b i n / j a v a c 1 0 6 1 m a n u e l l e rM o d u s D r c k e nS i ed i eE i n g a b e t a s t e ,u md i ea k t u e l l eW a h l [ * ]b e i z u b e h a l t e n , o d e rg e b e nS i ed i eA u s w a h l n u m m e re i n :1 u p d a t e a l t e r n a t i v e s :/ h o m e / j d k 1 . 6 . 0 _ 3 0 / b i n / j a v a cw i r dv e r w e n d e t ,u m/ u s r / b i n / j a v a c( j a v a c )i mm a n u e l l e rM o d u sb e r e i t z u s t e l l e n . d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $j a v av e r s i o n j a v av e r s i o n" 1 . 6 . 0 _ 3 0 e a " J a v a ( T M )S ER u n t i m eE n v i r o n m e n t( b u i l d1 . 6 . 0 _ 3 0 e a b 1 0 ) J a v aH o t S p o t ( T M )S e r v e rV M( b u i l d2 0 . 5 b 0 2 ,m i x e dm o d e ) d a n i e l s @ d a n i e l s X 6 8 1 X : / u s r / b i n $

Reply 23 S O February 28, 2012 at 4:33 pm Thank you Reply 24 archagy May 14, 2013 at 7:46 pm Thanks very helpful Reply 25 vishal joshi January 9, 2009 at 11:07 am Dear Mustafa Buljubasic, thanking YOu so much. i need one more help.how to install tomcat and how to set environmental variable for that on linux. Reply
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 8/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

26 Rudra January 20, 2009 at 10:31 am You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users: [# vi /etc/profile] Next setup PATH / JAVA_PATH variables as follows: [export PATH=$PATH:/usr/java/jdk1.5.0_07/bin] [export PATH=$PATH:/usr/java/jdk1.5.0_07/bin] Reply 27 Pratap July 27, 2011 at 12:11 pm Why do we need to SET path 2 times the same path?? Reply 28 notgzus July 28, 2011 at 6:07 pm i think he ment: export JAVA_HOME=$JAVA_HOME:/usr/java/jdk1.6.0_26/bin/java export PATH=$PATH:/usr/java/jdk1.6.0_26/bin Reply 29 neha February 14, 2009 at 1:45 pm hi can some one please help me out .. i just installed java 1.6 on REDHAT 5 system do i need 2 set da classpath or just path n javahome is sufficient .. i tried settng all da 3 bt i guess it didnt work .. can ne1 tel me wts da correct procedure to do it .. Reply 30 Hermes Costell April 21, 2009 at 4:07 pm Mustafa: THANK YOU! These step-by-step instructions youve posted were exactly what I needed to install the JDK on RHEL 5.x I am floored that there was no link or mention from Suns website on how to do this. Do they actually WANT people to use Java? If so it seems to me that if they provided instructions such as these along with the downloads that it would help their product get out a great deal. Oh well. Reply 31 Saurabh April 23, 2009 at 1:59 pm Hi I am uing mandriva I ran export PATH=$PATH:/usr/lib/jvm/java-1.6.0-sun-1.6.0.06/jre/bin export JAVA_HOME=/usr/lib/jvm/java-1.6.0-sun-1.6.0.06/jre/bin/java but got errors saying

http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

9/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

: line 234: /usr/lib/jvm/java-1.6.0-sun-1.6.0.06/jre/bin/java/bin/java: Not a directory Please Help me Reply 32 Nagendra May 28, 2009 at 11:02 am Dear Saurabh, You have exported full path till bin in JAVA_HOME, Just set export JAVA_HOME=/usr/lib/jvm/java-1.6.0-sun-1.6.0.06/jre and it will work. Reply 33 sasa June 18, 2009 at 2:05 pm Thx to Mustafa. Your solution has been like Ado said ko kec na desetku sve najbolje Reply 34 Alok Guha June 24, 2009 at 10:12 am Thanks.. it worked. Reply 35 Anuvrat Parashar October 1, 2009 at 4:03 am I am using Mandriva Spring 09 and am trying to install IBM WebSphere and Eclipse on it. Eclipse runs fine but WebSphere says something goes wrong and does not start up. OpenJDK gets installed by default and JRE_HOME is set to the one for OpenJDK. I think that the trouble is because WebSphere does not support OpenJDK. I tried the above methods to export JRE_HOME=/usr/java/jre1.6.0_14/bin but it does not seem to work. especially when i ran source ~/.bash_profile it gave this error: bash: TMOUT: readonly variable help me out. Reply 36 Prakash May 20, 2010 at 5:48 am I installed jre-7 beat onto /opt .I appended the PATH of bin of java to /etc/environment variable and it works. Reply 37 Arivillathamalayali May 20, 2010 at 6:52 am java_vm throws out error java_vm process: could not find Java VM symbols ,Any Idea how to set PLUGIN_HOME variable for a jre 7 install(manually installed from jar archive) Reply 38 ChromeFan May 23, 2010 at 12:21 am Hi , set JAVA_HOME and PATH variables for every user under my Linux system(ubuntu 10.04)
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 10/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

open profile $sudo vi /etc/profile; insert into last line: #set java environment JAVA_HOME=/usr/lib/jvm/java-6-sun // I am using jdk1.6.0.20 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME export CLASSPATH export PATH export GDK_NATIVE_WINDOWS=true #this is for setting eclipse #env GDK_NATIVE_WINDOWS=1 #me too! close and save it #shell source /etc/profile //let profile work reboot Test if Java environment is successfully installed by typing in this in the shell: echo $JAVA_HOME echo $PATH Reply 39 Khan June 18, 2010 at 3:14 am Hi ChromeFan, can u please help me in setting up theh enviromental variables in php.ini file as well. thanks Reply 40 andy August 18, 2010 at 7:30 pm I also like to learn how to change environment variables, like CLASSPATH and LD_LIBRARY_PATH in php.ini. thanks! Reply 41 Dev September 6, 2010 at 10:13 am hito everybdy, i have two versions of java installed on my system jdk1.5 and jdk 1.6. Now i want to make my jdk1.6 as the default version. I do not want to overwrite jdk 1.5. So plz send me the proceedure to solve this issue. Reply 42 Dev September 6, 2010 at 10:23 am I want to implement all this on linux(fedora). Reply 43 Yogesh September 16, 2010 at 4:51 am Vivek, Im waiting for a tomcat howto :-) Reply 44 Dev September 17, 2010 at 5:27 am
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 11/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

hi to evrybdydear yogesh dere is nothing much typical to wait for a tomcat..if u wan to set this on ur system then just set the path variable in /etc/bashrc file for all users..actually in my case problem is that i want to implement this for my server.so plz send a correct information rather than any funny remarks. Reply 45 Yogesh September 17, 2010 at 5:40 am @Dave, with tomcat howto I mean a complete step by step guide to deploy tomcat app server and integrate it with existing apache with the help of mod_jk. And not just setting the path variable in /etc/bashrc as you said. Setting path is something which I have learnt in my nursery rhymes. By the way the comment I posted was for site owner Vivek Gite and not you. Please read it again and dont comment until you are very sure about it!! Reply 46 Dev September 20, 2010 at 5:12 am oh great if uve learnt dis in ur nuresery rhymes den def u would be the right person who can help me to solve this..sory for misunderstnding. Actualy i m trying to set this path for long so .. Reply 47 Dev September 20, 2010 at 5:13 am oh great if uve learnt dis in ur nuresery rhymes den def u would be the right person who can help me to solve this..sory for misunderstnding. Actualy i m trying to set this path for long so. Reply 48 soothsayer October 6, 2010 at 6:25 pm I dont know what everyone else is saying. I just read the first couple of posts from people and found some people having issues with this.. However I just wanted to thank the person who wrote this article at the first place. The instructions worked perfect for me.. thanks a lot. Reply 49 Shanaka November 5, 2010 at 5:02 am Thanks This is very useful.. Reply 50 Karthigayan February 23, 2011 at 5:10 am Thanks. This is excellent. This was very useful. Thank Musthafa Reply 51 H.Martin March 17, 2011 at 6:24 pm This does not work! Reply 52 Mohammed April 20, 2011 at 7:04 am Dear all, Can anyone help me? Ive installed jdk 1.6 update 24 and while opening appliciton its downloadin jdk 1.5,
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 12/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

from backend its showing 1.6 update 24, ive tried multiple noluck. Regards, Fareed. Reply 53 haasdas May 14, 2011 at 6:53 pm I came across this: sudo update-java-alternatives -s java-6-openjdk (ubuntu 10.10 for me) It seems to do a lot of stuff automatically! Hope it helps some people out there Reply 54 NARESH May 23, 2011 at 12:03 pm /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../lib64/crt1.o: In function `_start: /usr/src/packages/BUILD/glibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main collect2: ld returned 1 exit status HOW TO SOLVE THIS PROBLEM PLEASE TELL ME MY OS IS LINUX OPEN SUSE AT THE TIME OF COMPILATION THIS ERROR APPEARED Reply 55 mathi June 13, 2011 at 12:23 pm Thanks a lot ..I also faced this problem for last three week. After seeing ur post, did what u explained here.Now working ya.. Reply 56 alsat June 13, 2011 at 5:27 pm I installed sun-java from synaptic package manager and to initialize these variables i did as explained above.. bt i thnk dr z sth wrong wid it.. i cannot start websphere because it returnd an error wid dese variables.. Can any1 tel me wts d proper way of setting these variables and path and in what all files so that it is set for all users system wide? thnx! Reply 57 RT July 27, 2011 at 2:48 pm I keep getting a dependency problem when trying to install tomcat6 on rhel5: omcat6-6.0.29-1.jpp5.noarch from jpackage-generic-updates has depsolving problems > Missing Dependency: java is needed by package tomcat6-6.0.29-1.jpp5.noarch (jpackage-generic-updates) tomcat6-6.0.29-1.jpp5.noarch from jpackage-generic-updates has depsolving problems > Missing Dependency: java is needed by package tomcat6-6.0.29-1.jpp5.noarch (jpackage-generic-updates) Error: Missing Dependency: java is needed by package tomcat6-6.0.29-1.jpp5.noarch (jpackage-generic-updates) But, java is installed correctly as far as I can see. java -version returns java version 1.6.0_26 Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 13/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) Reply 58 RT July 27, 2011 at 2:52 pm environment variables are setup correctly env returns: JAVA_HOME=usr/java/jdk1.6.0_26 PATH=usr/java/jdk1.6.0_26/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/admin/bin Reply 59 Sam November 7, 2011 at 3:37 am Linux Mint 10.10 (should work the same in Ubuntu 10.10) By default you should be able to type: $ which java and get: /usr/bin/java /usr/bin/java is actually a symbolic link to /usr/lib/jvm/default-java If you try to set /usr/bin/java as JAVA_HOME, you will have problems. As a workaround, you should be able to set JAVA_HOME successfully using: export JAVA_HOME=/usr/lib/jvm/default-java export PATH=$PATH:$JAVA_HOME/bin Reply 60 Pablo February 2, 2012 at 1:22 pm Voc sauvou minha vida! Obrigado! You sauve my life! Thank you! Reply 61 spring March 21, 2012 at 5:10 pm theres error in the article, export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java should export JAVA_HOME=/usr/java/jdk1.5.0_07/ Reply 62 ZehcnasAlex May 22, 2012 at 3:35 pm Hi, maybe if youll try with apt-get install maven2, i did it in this way and still i dont have any problem. Reply 63 yaseen May 31, 2012 at 8:23 am Dear Guru,
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 14/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

I am new to sap.please send me document hot to install gateway instance using xmanager.please help me to this issue.my os is Linux susi 11 and database is oracel Regards Yaseen Reply 64 eb July 16, 2012 at 2:45 am This article is stupidly wrong and user spring above is correct. First find out where your jdk is installed. Then set as below: export JAVA_HOME=/usr/java/jdk1.6.0_18 After doing this way my Tomcat install worked fine. Reply 65 Gajesh September 14, 2012 at 12:35 pm Hi I have installed cygwin for windows xp, can you please tell me how to set JAVA_HOME variable? its not taking the windows path. Reply 66 seighalani December 16, 2012 at 8:59 pm hi thanks for your good article. please correct end of article. there is duplicate phrase . i mean Next setup PATH / JAVA_PATH variables as follows: export PATH=$PATH:/usr/java/jdk1.5.0_07/bin export PATH=$PATH:/usr/java/jdk1.5.0_07/bin Reply 67 Anugya February 26, 2013 at 12:49 pm Thank It help me lot!!!!!!!!!!!!!!!! Reply 68 sanjib deka April 16, 2013 at 9:30 am I have installed jdk1.7.0.17. when i check java version and path it shows OpenJDK version and the path like /usr/lib/jvm/jre-1.7.0-17-openjdk.x86-64/bin/java. How can change it to : java version 1.7.0_17 Java(TM) SE Runtime Environment Java HotSpot(TM) Server VM kindly help me please. Reply
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 15/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

69 ash7 July 3, 2013 at 5:33 am To summarise and simplify the procedure. The following would set the env variables for the particular user. Step 1. Open the ~/.bashrc file nano /home/user/.bashrc Step 2: Set the environment variables as follows. Just put these on the top of the file and save it. # user defined environment variables # export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64 export PATH=$PATH:/$JAVA_HOME/bin Step 3. Logout and login again. Step 4. Open terminal and type echo $JAVA_HOME and echo $PATH this should return you the appropriate result as you had set. Note: I have my java installed at /usr/lib/jvm/java-1.6.0-openjdk-amd64 location. It may vary in your system. Reply 70 Atul September 10, 2013 at 5:34 pm Thanks ash7 ! its Working.. Reply 71 Kiss September 11, 2013 at 10:49 am I searched .bashrc in file system and i found 2 files bash.bashrc and 2 files dot.bashrc how can i choose the right one? in my home/user/ there is no file .bashrc please help me! Reply 72 sam ben March 27, 2014 at 7:29 pm yeah it worked for me .. thanks man Reply 73 Atul September 10, 2013 at 5:29 pm System Got stuck!!! Reply 74 saji November 6, 2013 at 11:14 am i have problem for running selenium script in linux machine i have received this error kindly help me out or pls give me messge ill cal clarify error mention below com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to /usr/lib/jvm/java-7-openjdk-i386/jre
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ 16/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Reply Leave a Comment Name * E-mail *

Notify me of followup comments via e-mail


Submit

Tagged as: export command, export path, java executable, java home variable, java jdk1, linux system, path variable, path variables, set environment variables, set PATH, startup script, vi command Previous Faq: How to: Turning off SFTP server under Linux / UNIX cpanel server Next Faq: Linux: Find out what kernel drivers (modules) are loaded

To search, type and hit enter

nixCraft
Follow
+ 13,575

+1

http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

17/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Related Faqs

UNIX / Linux: Set your PATH Variable Using set or export Command

How to: Change Users bash profile under Linux / UNIX

http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

18/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Display or print UNIX / Linux path ~ $PATH variable

HowTo Run a Script In Linux

Linux: Change the PATH [ Add New Directory ]

Disable Caps Lock Key in Linux

Linux / Unix: Bash Shell See All Exported Variables and Functions

How To Read / Print $PATH Shell Variable

Bash Shell Script Function Examples

http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

19/20

4/11/2014

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Change default Linux / UNIX text editor from VI to Pico

Latest posts from our blog


Linux and Unix nload App: Monitor Network Traffic and Bandwidth Usage In Real Time 10 Linux/Unix Bash and KSH Shell Job Control Examples Download of The Day: FreeBSD 10 ISO DVD / CD Images 30 Cool Open Source Software I Discovered in 2013 Download Of The Day: Fedora Linux 20 (Heisenbug) CD / DVD ISO Tweets by @nixcraft

Subscribe to nixCraft
Learn something new about Linux/Unix by email Enter your email address:

Subscribe

2000-2014 nixCraft. All rights reserved. Privacy Policy - Terms of Service - Questions or Comments - We are proudly powered by Linux + Nginx + WordPress. The content is copyrighted to nixCraft and may not be reproduced on other websites.

http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

20/20

Vous aimerez peut-être aussi