Get into DevOps is a blog about methodologies, practices and tools to improve software delivery.

Starting in the shell: The PATH variable

Starting in the shell: The PATH variable

Generally the commands you run in a shell are either built-in commands, or external programs. Unless it is a command that’s built into your shell itself (such as ‘echo’, which just outputs whatever input you give it), the shell uses an environment variable called PATH to know which directories to look for an executable file.

See the PATH used by your shell by running echo $PATH

See where an external program actually is: which <program> For example:

$ which gulp
/usr/local/bin/gulp

Therefore, in my system, running gulp is synonymous to running /usr/local/bin/gulp. My shell knows where to find gulp, because the directory containing the binary is included in the PATH:

$ echo $PATH
/Users/mjuuso/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/Users/mjuuso/.rvm/bin

A real-world example of this would be why npm install gulp, followed by gulp doesn’t work as expected. When you install gulp with npm, it doesn’t (by default) install it into a directory included in your PATH.

To run gulp in this scenario, you would need to either add node_modules/.bin/ to your PATH, or run the executable explicitly with ./node_modules/.bin/gulp. A way around this is to install gulp globally:

npm install -g gulp

This will, by default, install the gulp executable in a directory that’s in your PATH: /usr/local/bin

Getting started with metrics

Getting started with metrics

Building a DevOps organisation

Building a DevOps organisation