In bash (and most other shells) you assign variables without the $
, so PATH=something
assigns the variable PATH
to the string "something"
.
In Unix/ Linux, PATH
is a string variable that contains a list of folders separated by colons (:
). For example on my laptop this is my PATH
:
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
This means that any executable in those folders is accessible anywhere without having to type the full path. You will typically add things to the PATH
in your .bashrc
file, so they get added when your shell starts up. If you use the which
command you can see where a command lives, it will be in one of these folders:
> which rm
/bin/rm
To add a new folder to the PATH
, you re-assign PATH
to be a string of the new folder, followed by a colon and the previous value of PATH
.
In you example, you are adding $HOME/.rbenv/bin
to the start of PATH
. $HOME
will be expanded to your home directory.
To understand this better we can do something like this:
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
> export PATH="$HOME/.rbenv/bin:$PATH"
> echo $PATH
/Users/javanut13/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
As you can see the rbenv
folder was added to the front of the PATH
variable.
export
puts the variable into the environment of the current shell, which means that other commands started in that shell (subprocesses) also get this change. For example if you don't do export
and then run a bash script that uses ruby
, it will fail because it doesn't have the ~/.rbenv/bin
folder in its path.