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

Published: Jun 23, 2021
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 ~

  1. Get familiar with macOS and Linux Environment Variables in Terminal

  2. Open Terminal

  3. Create directory ${HOME}/bin by running

     mkdir -p ${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 your shell config file 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 the below line to the shell config file, then save it

     export PATH="${HOME}/bin:${PATH}"
    
  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 "C:\bin;%PATH%"
    
  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 start of the variable value, followed by a ;. For example, if the value was C:\Windows\System32, change it to C:\bin;C:\Windows\System32

  8. Click OK

  9. Open Command Prompt

  10. Verify the binary.exe is on your PATH by running

     where.exe binary.exe
    
Reply by email