LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 07-18-2008, 04:21 PM   #1
oouc
LQ Newbie
 
Registered: Jul 2008
Posts: 6

Rep: Reputation: 0
Ubuntu 8.04 loses my $PATH. Why do I have to repeatedly export PATH= ?


I kept losing my path in Ubuntu 8.04 after running a certain program. Any help would be greatly appreciated.

js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ cat /media/hda9/56/programming/java/SetPath1_6_07.txt
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ sudo echo $Path

js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ /media/hda9/56/programming/java/SetPath1_6_07.txt
/media/hda9/56/programming/java/SetPath1_6_07.txt: line 1: /usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:: No such file or directory
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ sudo /media/hda9/56/programming/java/SetPath1_6_07.txt
[sudo] password for js:
/media/hda9/56/programming/java/SetPath1_6_07.txt: 1: /usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: not found
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ ls /usr/local/bin/jdk1.6.0_07/bin
appletviewer HtmlConverter java javap jcontrol jmap jstack keytool policytool schemagen unpack200
apt idlj javac java-rmi.cgi jdb jps jstat native2ascii rmic serialver wsgen
ControlPanel jar javadoc javaws jhat jrunscript jstatd orbd rmid servertool wsimport
extcheck jarsigner javah jconsole jinfo jsadebugd jvisualvm pack200 rmiregistry tnameserv xjc
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ ls /usr/local/bin/jdk1.6.0_07/jre
bin COPYRIGHT javaws lib LICENSE plugin README THIRDPARTYLICENSEREADME.txt Welcome.html
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ cat /media/hda9/56/programming/java/SetPath1_6_07.txt
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ export PATH=/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ echo $PATH
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$
 
Old 07-18-2008, 04:39 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
You should edit your post to be more readable. That god awful prompt is very distracting as are the very long file paths.


Quote:
Originally Posted by oouc View Post
I kept losing my path in Ubuntu 8.04 after running a certain program. Any help would be greatly appreciated.

cat SetPath1_6_07.txt
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

sudo echo $Path
Okay. So what? You typed a text file in one process under one identification and then you sudo to root and show that root has no path set. What's your point?

Quote:
Originally Posted by oouc View Post
/media/hda9/56/programming/java/SetPath1_6_07.txt
/media/hda9/56/programming/java/SetPath1_6_07.txt: line 1: /usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:: No such file or directory
I have no idea what this is about. Are you trying to run a text file?

Quote:
Originally Posted by oouc View Post
sudo /media/hda9/56/programming/java/SetPath1_6_07.txt
[sudo] password for js:
/media/hda9/56/programming/java/SetPath1_6_07.txt: 1: /usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: not found
It looks like you are trying to run a text file under root. File not found. No mystery here.

Quote:
Originally Posted by oouc View Post
ls /usr/local/bin/jdk1.6.0_07/bin
appletviewer HtmlConverter java javap jcontrol jmap jstack keytool policytool schemagen unpack200
apt idlj javac java-rmi.cgi jdb jps jstat native2ascii rmic serialver wsgen
ControlPanel jar javadoc javaws jhat jrunscript jstatd orbd rmid servertool wsimport
extcheck jarsigner javah jconsole jinfo jsadebugd jvisualvm pack200 rmiregistry tnameserv xjc

ls /usr/local/bin/jdk1.6.0_07/jre
bin COPYRIGHT javaws lib LICENSE plugin README THIRDPARTYLICENSEREADME.txt Welcome.html
Here you listed the contents of a directory.

Quote:
Originally Posted by oouc View Post
cat /media/hda9/56/programming/java/SetPath1_6_07.txt
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Repeat step 1. So what?

Quote:
Originally Posted by oouc View Post
export PATH=/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

echo $PATH
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Export PATH. Echo PATH.

It really isn't clear to me what you are talking about. The only thing that I can see is that you sudo to root and have no PATH set. Of course your normal user PATH does not export to a root login. Is that what you are wondering about?

As I say, edit your post to be more readable. Take out the extra commands like the directory listings, get rid of that prompt, and edit out the long file paths. For the purposes of this post you should be able to use a shorter PATH. Make it easy for us to understand you.

Last edited by stress_junkie; 07-18-2008 at 04:59 PM.
 
Old 07-19-2008, 12:29 AM   #3
oouc
LQ Newbie
 
Registered: Jul 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Please just tell me why I have a PATH then reboot and do not.

Sorry, I did give too much and irrelevant information.

Please just tell me why I have a PATH as you see at the end. But then reboot and do not as you see at the beginning.
 
Old 07-19-2008, 06:59 AM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by oouc View Post
I kept losing my path in Ubuntu 8.04 after running a certain program. Any help would be greatly appreciated.

js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ cat /media/hda9/56/programming/java/SetPath1_6_07.txt
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ sudo echo $Path

<snip>

js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ export PATH=/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$ echo $PATH
/usr/local/bin/jdk1.6.0_07/bin:/usr/local/bin/jdk1.6.0_07/jre:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
js@hh:/media/hda9/56/programming/ide/jEdit/4.3pre12$
Now that I read your original post again I can see that when you sudo to root to echo $PATH you have misspelled $PATH as $Path. So that's why that doesn't show any PATH.

The end shows that you set $PATH in the normal user account and then echo $PATH so that's why you have what you see in the last section.

So it looks like you are trying to list $PATH under the root account but you misspelled $PATH so you see nothing, then you export $PATH as a normal user and then list $PATH as that same normal user.

I'm going to make a big leap in guesswork to try to understand what you are thinking.

It seems that you believe that the first line in your example code should set your process path but it doesn't because the text file does not contain a verb. The text file simply contains the value that you want to use for your normal user PATH but you don't have a verb in the script so it is not a script. Even if it were a script you would ALSO have to have the execute permission bit set on the file. Maybe the execute permission bit is set or maybe it isn't. We don't know at this point. Your SetPath1_6_07.txt file should contain a verb such as you see in the following code example.
Code:
export PATH="/bin:/usr/bin"
Notice here the verb is export. Actually there are two verbs since the = symbol is also a verb. But running this won't set your PATH for your current process because when you run a script the bash shell spawns a child process to run the script. If you want a script to set your PATH for your current process then you have to "source" the script. That is a special verb in bash that tells the command interpreter to run the script in the current process. Here is an example.
Code:
. SetPath1_6_07.txt
You would do that at the command line.

Then you sudo to root and echo $PATH but since you misspelled $PATH you see nothing. I believe you expect that the PATH that you thought that you set under the normal user account should export to the root login under sudo but it won't. When you use sudo it is a separate login for root and nothing from your normal user environment will export to the root environment.

The last section is the first time that you successfully set PATH anywhere in the example code. Naturally when you then echo $PATH it shows the value that you had just set in the PATH variable. I want to emphasize that this is the first time that you successfully set the PATH variable anywhere in your example code.

I hope this helps. I wouldn't have taken the time to write this if I didn't sincerely want to help you to understand. If I have misunderstood your question please let me know.

Last edited by stress_junkie; 07-19-2008 at 07:35 AM.
 
Old 07-19-2008, 07:12 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,803

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by oouc View Post
But then reboot and do not as you see at the beginning.
Assuming that you set your PATH correctly, you can still lose it at reboot---the init scripts, etc. will set the PATH. To make any change permanent, you have to modify the init scripts.
 
Old 07-19-2008, 07:23 AM   #6
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Hi. I've moved this to the Ubuntu forum for more exposure.

To set paths permanently, you need to do so in /etc/environment.
 
Old 07-19-2008, 07:39 AM   #7
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by reddazz View Post
Hi. I've moved this to the Ubuntu forum for more exposure.

To set paths permanently, you need to do so in /etc/environment.
I think that the essence of the question has to do with export and sudo where exported PATH does not carry over to an sudo session but it's really difficult to tell what the real question is. I think that the reboot is a red herring.

Last edited by stress_junkie; 07-19-2008 at 07:43 AM.
 
Old 07-19-2008, 09:34 AM   #8
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 132Reputation: 132
You need to set path globally in /etc/profile or on a user base in .profile (or both if you want your user to have different settings than the system wide ones).
 
Old 07-19-2008, 02:18 PM   #9
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Quote:
Originally Posted by stress_junkie View Post
I think that the essence of the question has to do with export and sudo where exported PATH does not carry over to an sudo session but it's really difficult to tell what the real question is. I think that the reboot is a red herring.
If the path is exported in /etc/environment, then its global and is available when someone uses sudo or su.
 
Old 07-20-2008, 11:02 PM   #10
oouc
LQ Newbie
 
Registered: Jul 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks to you all. I fixed it in /etc/profile

I added to /etc/profile 2 statements something like
export $JAVA_HOME=/usr/local/bin/jdk1.6.0_07/bin
and
export $PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/bin/jdk1.6.0_07/bin

now I can do this
js@hh:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/bin/jdk1.6.0_07/bin
js@hh:~$ echo $JAVA_HOME
/usr/local/bin/jdk1.6.0_07/bin
js@hh:~$ which java
/usr/local/bin/jdk1.6.0_07/bin/java

Thanks again everyone for all of your advice,
oouc
 
Old 09-14-2009, 12:54 AM   #11
oouc
LQ Newbie
 
Registered: Jul 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Do not use $ before JAVA_HOME or PATH

You can add to /etc/profile these 2 statements
export JAVA_HOME=/usr/local/bin/jdk1.6.0_07/bin

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/bin/jdk1.6.0_07/bin

then from the terminal do
source /etc/profile

If everything else was right then the command
which java
will tell you which java you are using.

Thanks again to everyone. Special thanks to linuxquestions.org.
I Googled for hours and got the wrong stuff in several forums then remembered that you had helped me find the right answer here.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
export PATH problem arnuld Fedora 13 12-13-2007 11:01 AM
export Path=/usr/java:$Path does not seem to work lumix Linux - Newbie 1 03-19-2007 04:11 PM
problems with export (path) mac1234mac Linux - Software 2 03-17-2006 04:04 AM
export PATH Question Loosewheel Linux - Software 5 01-18-2006 02:44 PM
export PATH disappears twallstr Linux - General 4 12-13-2004 03:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 08:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration