How to Add a Binary (or Executable, or Program) to Your PATH on macOS, Linux, or Windows
Updated: Mar 9, 2022
I often find myself explaining how to do this. It’s time I get wise and write a generic doc on it.
We’ll assume you want to add a binary, named binary on macOS and Linux, and binary.exe on Windows, to your PATH. (How original, I know).
Enjoy.
macOS and Linux CLI #
Note: ${HOME} is also known as ~
-
Get familiar with macOS and Linux Environment Variables in Terminal
-
Open Terminal
-
Create directory
${HOME}/binby runningmkdir -p ${HOME}/bin -
Save the
binaryto directory${HOME}/bin -
Make the
binaryexecutable by runningchmod 755 ${HOME}/bin/binary -
macOS specific step
- Open your shell config file in a text editor. If the file doesn’t exist, create it
-
Linux specific step
- Open file
${HOME}/.bashrcin a text editor. If the file doesn’t exist, create it
- Open file
-
Add the below line to the shell config file, then save it
export PATH="${HOME}/bin:${PATH}" -
Restart your Terminal
-
Verify the
binaryis on yourPATHby runningcommand -v binary
Windows CLI #
-
Get familiar with Windows Environment Variables in Command Prompt
-
Open Command Prompt
-
Create folder
C:\binby runningmkdir C:\bin -
Save the
binary.exeto folderC:\bin -
Edit the
PATHfor your accountsetx PATH "C:\bin;%PATH%" -
Restart Command Prompt
-
Verify the
binary.exeis on yourPATHby runningwhere.exe binary.exe
Windows GUI #
-
Create folder
C:\bin -
Save the
binary.exeto folderC:\bin -
Depending on your Windows version
- If you’re using Windows 8 or 10, press the Windows key, then search for and select System (Control Panel)
- If you’re using Windows 7, right click the Computer icon on the desktop and click Properties
-
Click Advanced system settings
-
Click Environment Variables
-
Under System Variables, find the
PATHvariable, select it, and click Edit. If there is noPATHvariable, click New -
Add
C:\binto the start of the variable value, followed by a;. For example, if the value wasC:\Windows\System32, change it toC:\bin;C:\Windows\System32 -
Click OK
-
Open Command Prompt
-
Verify the
binary.exeis on yourPATHby runningwhere.exe binary.exe