The only Two Things You Need to Know About PATH Command Line

August 4, 2019

"I was a bit challenged when I was younger to stay on the right path" - Dwayne Johnson


Such wisdom. Not all path leads to happiness. The wrong PATH will lead you to unhappiness. Here we will learn the right path and stay in it!

There are many things you can learn about path. I think the two important ones are:

  1. Finding your path
  2. Updating your paths.

Finding your PATH

In mac, you can find path from command line by typing echo $PATH. Mine looks something like this:

echo $PATH

Path is colon (:) separated and it reads from left to right.

For example, if I execute node, my terminal would first search node executable at (/Users/iggy/.nvm/versions/node/v10.15.1/bin), then (/usr/local/bin), etc. If node was not found anywhere, it will return command not found: node.

To find which path node currently uses, run which node, in my case, I see:


Note the similarities between my one of my paths and node path:


#node path

Updating your path

You can either prepend or append your path


This type of change is temporary. It will disappear when the terminal is closed. To make it permanent, update path inside .bash_profile or .profile

export PATH="~/new/path:$PATH"

Application: let's hack a path!

Suppose you are an evil person and wanted to modify the node command of your coworker so when they run node, they are running your script instead. All you need is to prepend your own path so when they run node, path will execute your node executable first. Here is how you can do it:

Create /for-fun dir, inside create a file named node. Make sure to add #!/bin/bash (shebang) on first line:


Save, then grant permission chmod +x ./node. Adding shebang and permission are required so they can run node directly instead of ./node

Prepend path:


(replace Users/iggy/for-fun with whatever path you used. You can use pwd if you're not sure where you're at)

Check your newly appended path (echo $PATH) to make sure our prepend path is the first path displayed. Check also your node path (which node) - you should see the updated path.

Cool! Next time someone runs node, they'll see:


That's all folks. Happy hacking!!

© Copyright 2021 Igor Irianto