"add the binary to your path to make it available on the command line"
In Unix, the PATH
is the environment variable which defines where the shell looks for executable programs to run when you enter them on the command line. If you do a:
echo $PATH
You can see what your PATH
looks like. All of the directories on the PATH
are then searched (in order) when you type a command (like ls
). For example, my $PATH is:
.:/usr/local/bin:/usr/bin:/bin
When I type in ls
the shell will look for an executable in .
(the current directory) and then all of the other directories until it finds it, probably in /bin/ls
.
You will need to make sure your script is executable (chmod +x myscript
) and then it needs to be in one of the directories in the PATH
variable.
It's considered somewhat bad practice to install local scripts and programs in the system's bin directories. Typically I put something like the following in my shell's startup-config file which is .profile
but could be .bashrc
or .zshrc
depending on the shell:
export PATH=$HOME/bin:$PATH
This will add to the path a personal bin directory in your home directory where you can put your own scripts. Once you change the shell's config file you will need to login again to have the config file read.
If you want to install your script for all of the users on your system then a better place for your script is /usr/local/bin
. You should make sure that /usr/local/bin
is in your path using the above mechanism.
So you need to:
- Make your program executable (
chmod +x my-program
)
- Maybe add your own local bin directory or
/usr/local/bin
to the PATH
definition in your .profile
.
- Install it in a directory in your
PATH
environment.