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.
π. Similar posts
How to Easily Find All Folder Under a Linux Directory Matching Certain Criteria
10 Dec 2024
A Linux Script to Delete All the .git Folders Hidden in Your Repo Folders
18 Nov 2024
How to Beautifully Print the PATH environment variables on Linux
18 Oct 2024