Make java PATH env variable permanent


8 posts
by Sag73 » Wed Jan 02, 2013 2:48 pm
I am running the 1.8.0 JDK Prerelease for ARM on Raspbian and I have got it working smoothly but I keep having to put
Code: Select all
/opt/jdk1.8.0/bin/<java command>
. I can make it so I just have to put the java command by doing
Code: Select all
export PATH=$PATH:/opt/jdk1.8.0/bin
but the PATH variable seems to delete itself whenever I close the terminal window. What should I do to make the change permanent?
Posts: 11
Joined: Tue Jan 01, 2013 6:12 pm
by ukscone » Wed Jan 02, 2013 2:56 pm
to make it permanent you need to add the export line to your .bashrc

Code: Select all
echo "export PATH=$PATH:/opt/jdk1.8.0/bin" >> ~/.bashrc


will do the job
User avatar
Forum Moderator
Forum Moderator
Posts: 3844
Joined: Fri Jul 29, 2011 2:51 pm
by Sag73 » Wed Jan 02, 2013 3:05 pm
I did what you said but it came up with bash: /home/pi/: Is a directory. Am I doing something wrong?
Posts: 11
Joined: Tue Jan 01, 2013 6:12 pm
by ukscone » Wed Jan 02, 2013 3:11 pm
that error will occur if you put a space between the . and the b in bashrc. there are no spaces in the ~/.bashrc part of the command

ukscone@welham ~ $ echo "export PATH=$PATH:/opt/jdk1.8.0/bin" >> ~/. bashrc
-bash: /home/ukscone/.: Is a directory


either add the line using an editor or cut and paste the line below (if using your pi to read this post)

Code: Select all
echo "export PATH=$PATH:/opt/jdk1.8.0/bin" >> ~/.bashrc
User avatar
Forum Moderator
Forum Moderator
Posts: 3844
Joined: Fri Jul 29, 2011 2:51 pm
by Sag73 » Wed Jan 02, 2013 3:12 pm
Sorry. I made a mistake.

I thought there was a space between ~/ and .bashrc. You probably assumed I'd do this but I also had to do a reboot.

Thanks
Posts: 11
Joined: Tue Jan 01, 2013 6:12 pm
by ukscone » Wed Jan 02, 2013 3:16 pm
Sag73 wrote:Sorry. I made a mistake.

I thought there was a space between ~/ and .bashrc. You probably assumed I'd do this but I also had to do a reboot.

Thanks


yes actually the error will occur pretty much no matter where you put the space in that part of the command. sorry i forgot to say you'd need to login again to get it to take.
User avatar
Forum Moderator
Forum Moderator
Posts: 3844
Joined: Fri Jul 29, 2011 2:51 pm
by ota-kun » Thu Jan 03, 2013 12:25 am
Just use update-alternatives to bind the java command in your system.

Code: Select all
sudo update-alternatives --install "/usr/bin/java" "java" "/pathToVM/bin/java" 1
Posts: 36
Joined: Tue Jul 17, 2012 8:38 am
by lobBob » Mon Jun 19, 2017 4:32 pm
a follow up on the path variable thread. for teh install of opencv cmake needs to be able to see the $JAVA_HOME path as set from admin account. obvious solution is to set the export for the path in /etc/environment. what i can't figure out is why the variable is again lost after a reboot. are global enviromental variables on raspbian set somewhere else instead? thanks a bunch, Robert
Posts: 3
Joined: Mon Jun 19, 2017 4:07 pm