Jump to content

How to set PATH without rebooting?


Recommended Posts

I need to reset my $PATH to include my path to java (/usr/java/jdk1.5.0_06/bin)

 

so I did this :

 

export PATH=$PATH:/usr/java/jdk1.5.0_06/bin

 

when I did this from the same term

 

echo $PATH 

 

it included the new addition. However, when I did the same from a new shell which I opened, the PATH reverted to the old one. From my limited reading isn't "export PATH" supposed to add to the PATH variable for all subsequently opened terminals ?

 

In any case, I added the PATH to my ~/.bash_profile, so I'll get it next time I reboot. But I want to have this in my global PATH without rebooting, how to do it ? Thanks.

Link to comment
Share on other sites

If you put the export command in ~/.bash_profile, then logging out and then back in is enough.

If you put the command to a system wide (global) script, then you can (instead of rebooting) going telinit 1 and then back to telinit 5. Of couse going telinit 1 will stop some services temporarily.

Edited by scarecrow
Link to comment
Share on other sites

I restarted the session and could get the new PATH. I just thought there's a way to get the new PATH working for all terminals without logging out (by logging out, I stopped running processes like my Azureus).

 

I really thought export PATH would do it. That was what I got from this website : http://club.mandriva.com/xwiki/bin/KB/BasicsBshell5

 

export PATH=$PATH:/some/directory

 

If you now open a new terminal and type echo $PATH, you will see the new value of $PATH in this terminal, too. Notice, however, that the 'export' command only sets or changes variables for the terminal it is run in and terminals which are started after it has been run. Terminals which were already open will still have the old $PATH.

Edited by Turb0flat4
Link to comment
Share on other sites

it will only affect terminals/processes that are started after you set it.

 

what happens, is that processes inherit environmental variables from their parent process, and so when you start X, all the GUI apps that start inherit their variables from when you started. if you for example, click an icon on your kde panel, it will inherit PATH from the panel, which inherited at startup. the only way to reload the PATH to these apps, is to restart them.

 

James

Link to comment
Share on other sites

it will only affect terminals/processes that are started after you set it.

 

what happens, is that processes inherit environmental variables from their parent process, and so when you start X, all the GUI apps that start inherit their variables from when you started. if you for example, click an icon on your kde panel, it will inherit PATH from the panel, which inherited at startup. the only way to reload the PATH to these apps, is to restart them.

 

James

 

But even if I open up a Konsole window, do the export PATH thing and then try to open a new shell or a new window from that previous Konsole, the PATH in the newly spawned Konsole windows is stil the default PATH, not the new one I set.

 

Just trying to understand under what circumstances I can do this. Thanks.

Link to comment
Share on other sites

You can't, because it pulls stuff from your .bashrc file, and also from /etc/profile. If it's not specified in any of these, it will not pick the new statement.

 

You have to add it to one of these files, and log out of the system. If you don't log out, it won't pick up the new path statement, no matter what you try right now. This is because your system is running on the previous environment variables BEFORE you typed the path statement. And it won't pick up anything you type subsequently. You have to add it to a file, and then log off and back on again.

Link to comment
Share on other sites

You have to add it to one of these files, and log out of the system. If you don't log out, it won't pick up the new path statement, no matter what you try right now.

Not quite true, at least in my case. If I change my .bashrc and then open a new console, it does pick up the changed path statement. I don't have to log out and log back in again because the .bashrc is read and executed whenever a new bash session is started.

If you want the change to also affect terminals which are already open, maybe there's a way to manually execute the .bashrc file from each one? I tried "bash .bashrc" but that didn't seem to work too well...

Link to comment
Share on other sites

Ah, that's cool then, at least saves logging out. But what he was doing was just typing it in one terminal window, and expecting it to be active in a new one he opened.

 

OK, so add your export line to the .bashrc file in your home directory, then it will work fine for you. It won't work when typed manually at the command line.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...