Show how you can add /home/<yourusername>/bin to the $PATH variable. Use $HOME (or ~) to
represent your home directory.
Asked
Active
Viewed 2.2e+01k times
53
muru
- 197,895
- 55
- 485
- 740
user233233
- 725
- 1
- 7
- 8
2 Answers
73
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.
wxl
- 901
- 5
- 23
Swordfish90
- 958
-
2
-
6It is the same. If you try "echo $HOME" you will probably see the folder /home/user_name... – Swordfish90 Jan 08 '14 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 – Panther Jan 08 '14 at 19:54
-
9@bodhi.zazen Your
HOMEis not guaranteed to by at the same location on different systems. For example, I use the same.bashrcon Linux and MacOS, and hard-coding the full path would not work. – Gauthier Aug 16 '17 at 11:34
40
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
falconer
- 15,026
- 3
- 48
- 68
-
1In case
~/.profileis not loaded add this to your~.bashrc:PATH="$HOME/bin:$PATH"– rubo77 Jul 13 '14 at 10:50 -
What does "-d" do? This actually prepends several ~/bin into $PATH if you have multiple logins. – sdaffa23fdsf Feb 11 '15 at 12:48
-
-
@sdaffa23fdsf Do you have a documented example of the multiple
~/bin? In that case the~/.profilescript should be changed to check if~/binis already in the path before prepending it to$PATH. – WinEunuuchs2Unix Jun 12 '18 at 01:54 -
-
When exactly does
~/.profileget sourced? I used to think that sourcing the~/.bashrcfile with. ~/.bashrcalso sources the~/.profilefile, but I just proved to myself that is not the case! Rather, it's the other way around!: sourcing the~/.profilefile with. ~/.profileactually sources the~/.bashrcfile as well, so long as the default Ubuntu~/.profilefile is in-use, since it contains lines to do so if running bash. – Gabriel Staples Jul 05 '22 at 00:27 -
Note also that on Linux Ubuntu, a backup copy of your default
~/.profilefile resides in/etc/skel/.profile. Other default files are in the/etc/skel/directory too. – Gabriel Staples Jul 05 '22 at 00:43
/home/<yourusername>/binis a Special directory that gets automatically added to the $PATH after it's been created and~/.profileis reloaded. The duplicate target is about adding generic directories to the path such as/mary/had/a/little/lamb. – WinEunuuchs2Unix Jun 11 '18 at 23:38~/.profile! – muru Jun 12 '18 at 01:41/home/YOURNAME/binto the$PATH. It's done automatically. – WinEunuuchs2Unix Jun 12 '18 at 01:49~/.profile), this gets added to thePATH. For all other cases, the answers to the dupe will have to be used. *This is a dupe.* – muru Jun 12 '18 at 01:54/home/YOURNAME/binwhich means you don't want to add it to the path. This could account for duplicates mentioned in comments by @sdaffa23fdsf like the accepted answer here might cause. I've asked @sdaffa23fdsf for documented examples of multiple instances of~/binin the path. This question could almost be thought of as "What directories do you NOT WANT TO ADD TO THE PATH". – WinEunuuchs2Unix Jun 12 '18 at 01:58