To add a folder of a binary file to the PATH
environment variable on macOS, follow these steps:
Open your Terminal
Personally, I use macOS native terminal. But some developers prefer Hyper or CommanderOne
Edit the Bash or Zsh Profile
If you are using bash, you will edit the ~/.bash_profile
or ~/.bashrc
file.
If you are using zsh (the default shell on macOS since Catalina), edit the ~/.zshrc
file.
Use a text editor to open the file. For example, with vim, you can use:
vim ~/.zshrc
Add the Directory to PATH: Add the following line to the end of the file, replacing /path/to/directory with the actual path of the directory you want to add:
export PATH="$PATH:/Users/your-username-here/bin"
Save and Exit the Editor
In vim, press :wq
to save and CTRL + X to exit.
Apply the Changes: Reload the shell configuration by running:
source ~/.zshrc
(Replace ~/.zshrc
with ~/.bash_profile
or ~/.bashrc
if youβre using bash)
This will update your PATH variable with the new directory, allowing you to run executables located there directly from the terminal.
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn β’ Twitter β’ GitHub or Medium