MacOS Catalina and Beyond – Updating $PATH in ZSH (2020)

I’ve just moved from Fedora on my primary work laptop, to MacOS. It’s a change I’m pretty happy about, not because I had any trouble with Fedora, but the quality of my hardware has been upgraded in a big way. This transition has been pretty smooth overall, but I have needed to solve a few small details to make sure I’m not losing any features.

One of those has been adding the tool MTR back to my machine. This was pretty straight forward, as it’s a part of Brew, a sort of package manager for MacOS. The only issue was that once MTR was installed, it’s location wasn’t in my $PATH for the default terminal emulator used in MacOS Catalina, called Z Shell, or zsh.

I could have put a symlink in place to work around that, but instead I added it’s location ‘/usr/local/sbin’ to my path instead.

This was a simple as creating a .zshrc file in my home directory, and making sure the folder was in the list.

Step one is to pull your current $PATH information:

echo $PATH

This should respond back with the current list of folders in your default path. It looked like this on my machine:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

From the terminal, I then created a new file in my Home directory called ‘.zshrc’, and added in the data required. The leading period is very important. It’s a way to create a file that is hidden from normal view, and zsh won’t see it otherwise.

vi ~/.zshrc

Once in vi, enter insert mode by pressing the letter i on the keyboard. Then, we build the command we need. On the first line of the file, create the command to update your path:

export PATH={your current PATH information from the previous command}

And then append the new path you want to add, following the same format, which includes a colon between each path.

:/new/path

Then, you can save and quit. To do this in vi press the escape key, to leave insert mode, and then enter ‘:wq’ (colon w q), which will tell vi to save and quit. Then to be sure typed it all correctly, let’s look at the output with the cat command:

cat ~/.zshrc

You should see an output like this:

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin

With that complete, fully quit terminal and then relaunch. You should see the updated information when you re-run our first command again:

echo $PATH

There are lots of other items you can add to this file to customize your terminal, but that’s for another day…

Topslakr

One Reply to “MacOS Catalina and Beyond – Updating $PATH in ZSH (2020)”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.