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}/bin
by runningmkdir -p ${HOME}/bin
-
Save the
binary
to directory${HOME}/bin
-
Make the
binary
executable 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}/.bashrc
in 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
binary
is on yourPATH
by runningcommand -v binary
Windows CLI #
-
Get familiar with Windows Environment Variables in Command Prompt
-
Open Command Prompt
-
Create folder
C:\bin
by runningmkdir C:\bin
-
Save the
binary.exe
to folderC:\bin
-
Edit the
PATH
for your accountsetx PATH "C:\bin;%PATH%"
-
Restart Command Prompt
-
Verify the
binary.exe
is on yourPATH
by runningwhere.exe binary.exe
Windows GUI #
-
Create folder
C:\bin
-
Save the
binary.exe
to 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
PATH
variable, select it, and click Edit. If there is noPATH
variable, click New -
Add
C:\bin
to 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.exe
is on yourPATH
by runningwhere.exe binary.exe