Show how you can add /home/<yourusername>/bin
to the $PATH
variable. Use $HOME
(or ~
) to
represent your home directory.
2 Answers
To do that you need to type in your terminal:
export PATH="$HOME/bin:$PATH"
This change is only temporary (it works only in the current session of the shell). To make it permanent, add the line to your .bashrc file located in your home directory.
-
2
-
6It is the same. If you try "echo $HOME" you will probably see the folder /home/user_name... Jan 8, 2014 at 19:51
-
$HOME is a variable and is thus ambiguous. IMO it is best to use the full path in scripts and when adding to your $PATH– PantherJan 8, 2014 at 19:54
-
9@bodhi.zazen Your
HOME
is not guaranteed to by at the same location on different systems. For example, I use the same.bashrc
on Linux and MacOS, and hard-coding the full path would not work.– GauthierAug 16, 2017 at 11:34
Ubuntu (and Debian based distros) automatically add $HOME/bin
to the PATH if that directory is present. You can check this in ~/.profile
:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
-
1In case
~/.profile
is not loaded add this to your~.bashrc
:PATH="$HOME/bin:$PATH"
– rubo77Jul 13, 2014 at 10:50 -
What does "-d" do? This actually prepends several ~/bin into $PATH if you have multiple logins. Feb 11, 2015 at 12:48
-
-
@sdaffa23fdsf Do you have a documented example of the multiple
~/bin
? In that case the~/.profile
script should be changed to check if~/bin
is already in the path before prepending it to$PATH
. Jun 12, 2018 at 1:54 -
/home/<yourusername>/bin
is a Special directory that gets automatically added to the $PATH after it's been created and~/.profile
is reloaded. The duplicate target is about adding generic directories to the path such as/mary/had/a/little/lamb
.~/.profile
!/home/YOURNAME/bin
to the$PATH
. It's done automatically.~/.profile
), this gets added to thePATH
. For all other cases, the answers to the dupe will have to be used. This is a dupe.