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

Published: Jun 23, 2021
Updated: Mar 9, 2022

Table of Contents

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
How to Add a Binary (or Executable, or Program) to Your PATH on macOS, Linux, or Windows (2024)

FAQs

How to add binary executable to PATH? ›

Adding the bin directory to your PATH
  1. Go to Control Panel > System Properties > Advanced > Environment Variables.
  2. Select PATH and click Edit.
  3. Append a semi-colon (;) followed by the "bin" directory path.
  4. Click OK twice to save.
  5. Start a new command shell window.

How to add executable file to PATH in Linux? ›

Linux: Add to PATH Permanently
  1. Open the . bashrc file using a text editor. ...
  2. Go to the end of the file.
  3. Paste the export syntax at the end of the file. export PATH="/Directory1:$PATH"
  4. Save and exit.
  5. Execute the script or reboot the system to make the changes live. To verify the changes, run echo :
Sep 22, 2022

How do I add a program to the PATH on my Mac? ›

The way that macOS recommends is to add a file into the “ /etc/paths. d/ ” directory. When you start a new terminal session, macOS will automatically read these files and add the folders to your path environment variable.

How to add bin to PATH in macOS? ›

In a shell you may type 'setenv PATH ~/bin:$PATH'. This would add the directory ~/bin to your path. Again, this will create a path to your bin directory inside your home directory. Also, when using this method, the variable will not become active untill you open up a new shell or run 'source .

How do I make a binary file executable in Linux? ›

Executing With the File Manager
  1. Open File Manager and navigate to the directory containing the program file (a shell script or a binary program file).
  2. Right-click on the file and click Properties.
  3. Click the Permissions tab.
  4. Select the Allow executing file as program option.
  5. Close the Properties window.

How do I add an exe file to the path in Windows? ›

  1. From start menu > Type "Environment Variables" and press Enter.
  2. System Properties > Advanced > Environment Variables.
  3. Find "Path" and double click on it.
  4. Click on New and enter the Path of the .exe file without adding the .exe file at the end.
  5. Click Ok on all Windows and you should be good to go.
Jan 27, 2011

How do I add a program to the PATH? ›

In the System Variables section scroll to Path. Click Edit then at the very end of the text box, paste the full path to the folder where the program file is located, but make sure not to replace any existing entries. The list is semi-colon separated. Click OK to close the dialogs.

How do I give a file PATH in Linux terminal? ›

How to Get the Full Path of a File in Linux
  1. Method 1: The “readlink” Command.
  2. Method 2: The “realpath” Command.
  3. Method 3: The “dirname” Command.
  4. Method 4: The combination of “basename” and “dirname” commands.
  5. Method 5: The “find” Command.
  6. Method 6: The “ls” Command.
Jan 2, 2023

Where is path file on Mac? ›

Show the path to a file or folder
  1. On your Mac, click the Finder icon in the Dock to open a Finder window.
  2. Choose View > Show Path Bar, or press the Option key to show the path bar momentarily. The location and nested folders that contain your file or folder are displayed near the bottom of the Finder window.

How to find path of file on Mac Terminal? ›

Step 1: Open Terminal as you normally would or by going to the Utilities folder and selecting the application. Step 2: When the Terminal window opens, drag your file or folder into it. You'll then see the file path display in the window.

What is the bin directory in Windows? ›

bin is folder every drive in system has in its root, eg C:\, and used as Recycle Bin, for deleted files.

How to add Python binary to PATH? ›

A more convenient solution is to add the directory containing the Python executable to the Path variable. For example, if Python is installed in C:\PythonXX\, you can add C:\PythonXX\ to the Path variable. Then, you can simply type Python in the Command Prompt from any directory, and it will work without errors.

How do I add a program to $path? ›

Adding a Program Folder to the Windows PATH
  1. Right click on Computer and go to Properties.
  2. In the Properties window, click Advanced System Settings.
  3. On the Advanced tab, click the Environment Variables button.
  4. In the System Variables section scroll to Path.

How do I add an executable to a PATH in Python? ›

  1. Step 1: Find Python Installation Directory.
  2. Step 2: Locate PATH Variable Options.
  3. Step 3: Add Python Directory to PATH.
Dec 28, 2023

How do I add code to terminal PATH? ›

Enable VS Code in your terminal

Press command + shift + p to open the command palette, then type "install code", and then click Shell command: Install 'code' command in PATH.

Top Articles
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 5501

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.