Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix: Getting Export PATH to "Stick"

When setting the export path in Unix, example:

export PATH=$PATH: $EC2_HOME/bin

If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time. I'm wondering how I can set the path and have it "stick" so my system knows where to find everything the next time I open terminal without having to do it all over again. Thanks!

like image 328
btw Avatar asked Oct 16 '08 15:10

btw


People also ask

How do I get the PATH of a file in Unix?

Firstly, we use the dirname command to find the directory in which a file is located. Then we change the directory using the cd command. Next, we print the current working directory using the pwd command. Here, we have applied the -P option to show the physical location instead of the symbolic link.

What is export PATH in Unix?

The export command sets and/or exports variables to the environment. It is equivalent to typeset –x, except when used within functions. Here, the PATH variable is set and exported: $ export PATH=$PATH:/usr/5bin. Multiple variables can be given to the export command.

How do you set the PATH in Unix?

To modify your path In all cases, replace /dir/path with the directory you want the shell to search. Note: Earlier entries in the path take precedence over later ones. If you want the directories you add to your path to take precedence, in the examples above, replace $PATH\:/dir/path with /dir/path:$PATH .


2 Answers

Open ~/.bashrc. This file is loaded every time you start up a new shell (if you're using Bash, which most people are). If you're using a different shell, the file may have a different name, like ~/.shrc.

Add the line you need to the bottom of the file:

export PATH=$PATH:$EC2_HOME/bi

Other info rolled up from elsewhere in the thread:

There are multiple places to put this, depending on your shell and your needs. All of these files are in your home directory:

For Bash:

.bashrc (executed when you shart a shell)

OR

.bash_profile (executed when you log in)

For csh and tcsh:

.cshrc

For sh and ksh:

.profile
like image 191
JSBձոգչ Avatar answered Sep 27 '22 21:09

JSBձոգչ


Add it to your .cshrc file (for csh and tcsh), .profile file (for sh and ksh), or .bash_profile file (for bash)

like image 21
itsmatt Avatar answered Sep 27 '22 21:09

itsmatt