Skip to main content

How to Add a Binary (or Executable, or Program) to Your PATH on macOS, Linux, or Windows

Published: 2021-06-23 • Last updated: 2021-07-05

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} or $HOME is also known as ~

  1. Get familiar with macOS and Linux Environment Variables in Terminal
  2. Open Terminal
  3. Create directory ${HOME}/bin by running
    mkdir ${HOME}/bin
    
  4. Save the binary to directory ${HOME}/bin
  5. Make the binary executable by running
    chmod 755 ${HOME}/bin/binary
    
  6. macOS specific step
    1. Open file ${HOME}/.bash_profile in a text editor. If the file doesn’t exist, create it
  7. Linux specific step
    1. Open file ${HOME}/.bashrc in a text editor. If the file doesn’t exist, create it
  8. Add line export PATH="${PATH}:${HOME}/bin" to the file, then save it
  9. Restart your Terminal
  10. Verify the binary is on your PATH by running
    command -v binary
    

Windows CLI

  1. Get familiar with Windows Environment Variables in Command Prompt
  2. Open Command Prompt
  3. Create folder C:\bin by running
    mkdir C:\bin
    
  4. Save the binary.exe to folder C:\bin
  5. Edit the PATH for your account
    setx PATH "%PATH%;C:\bin"
    
  6. Restart Command Prompt
  7. Verify the binary.exe is on your PATH by running
    where.exe binary.exe
    

Windows GUI

  1. Create folder C:\bin
  2. Save the binary.exe to folder C:\bin
  3. 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
  4. Click Advanced system settings
  5. Click Environment Variables
  6. Under System Variables, find the PATH variable, select it, and click Edit. If there is no PATH variable, click New
  7. Add ;C:\bin to the end of the variable value. Notice the preceding ;. For example, if the value was C:\Windows\System32, change it to C:\Windows\System32;C:\bin
  8. Click OK
  9. Open Command Prompt
  10. Verify the binary.exe is on your PATH by running
    where.exe binary.exe