How to Reset the PATH Variable on Mac to Default macOS PATH

Restore macOS PATH environment variable!

by: - Last updated on: September 13th, 2021
Key Takeaways
  • Modifying or setting the PATH environment variable on Mac isn’t easy if you don’t have prior experience.
  • Doing so can sometimes accidentally mess up your Mac’s existing PATH environment configuration and render the terminal nearly useless, preventing you from Mac terminal commands and programs.
  • Fixing a bad PATH on Mac requires you to reset the PATH environment variable to the default macOS PATH entries. And the guide below demonstrates the steps involved in this process.

Configuring the PATH environment variable for a program or script you need to use often enables you to execute them from any directory on your file system without specifying the absolute path where they are stored or installed.

reset PATH on Mac

However, while you’re at it, there are times when you accidentally mess up the existing (read default) PATH environment configuration on your system. On Windows, this isn’t a problem since it takes only one step to restore the default state of the PATH variable.

But if you’re on Mac, this isn’t as straightforward. And so, to simplify this equation, here’s a guide detailing the steps required to reset the PATH variable to its default state.

When Would You Want to Reset the PATH Variable in macOS?

To give you a brief idea of the need to reset the PATH variable, consider a scenario where you accidentally mess up—delete or update—the existing PATH environment variable on your Mac with incorrect program paths.

When this happens, all your existing terminal commands, including the basic commands such as ls, cd, where, mkdir, rmdir, etc., stop working and throw the command not found error. As a result, it renders the terminal nearly useless, keeping you from performing various system operations.

How to Reset the PATH Variable in macOS

Resetting the PATH variable in macOS involves editing either the shell config file or shell profile file and adding the default paths to it. Just like most operations on macOS, this can be done in two ways: GUI and CLI.

Resetting macOS PATH Variable via CLI

Since setting the PATH for a program or shell script on macOS requires interacting with the terminal; you’ve likely messed up your PATH somewhere along the way. And hence, the obvious approach to reset it is via the terminal itself.

But as you’d guess, this isn’t possible right away because a messed-up PATH means you can’t use any terminal command. So to overcome this, we first need to set the PATH temporarily such that we can use the terminal to navigate directories and edit the PATH configuration file, which is required to reset the PATH variable.

Enter the following command in the terminal and hit Return to set the PATH temporarily:

export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Next, open either the config file or the profile file for your shell. If you’re on older versions of macOS (before Catalina), the default shell on your system is bash, in which case you can open either the .bashrc or the .bash_profile file. On newer versions of macOS (Catalina or above), you’d have zsh (or z shell) as the default shell—unless you’ve changed it to bash. And so, you must edit either the .zhrc or the .zsh_profile file.

Now, depending on the shell you’re using, run any one of the following commands:

For bash

nano ~/.bash_profile
or
nano ~/.bashrc

For zsh

nano ~/.zsh_profile
or
nano ~/.zshrc

Once inside any of these files, you need to add all the default paths to the PATH environment variable using the command below:
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

reset Mac PATH via CLI

Hit Control + O to write your changes. When prompted to confirm the file name, hit Return. Press Control + X to exit the editor.

Close the active terminal window and reopen it to start a new session. Alternatively, you can run the command below to apply the changes immediately:

source ~/.bashrc
or
source ~/.bash_profile

Replace .bashrc or .bash_profile with .zshrc or .zsh_profile if your system’s default shell is zsh.

Finally, verify if the PATH has been set—and reset to the default PATH settings—correctly by running:
echo $PATH

viewing default macOS PATH entries

If the shell returns a list of all the different paths, that means your PATH environment variable has been reset, and so, you can resume using various macOS terminal commands on it as you did before.

Resetting macOS PATH Variable via GUI

In case you aren’t comfortable working with the CLI or find the whole process a bit tedious, you can use the GUI approach, which is rather straightforward.

For this, open the Finder and go to the root directory > Users > your_user_account directory and hit the Command + Shift + . shortcut to view all the hidden files in it.

reset Mac PATH via GUI

Next, depending on the active shell on your system, find any one of the following files: .bashrc, .bash_profile, .zshrc, or .zsh_profile. Right-click on a file and select Open With > TextEdit.

reset Mac PATH via GUI

When the file opens in TextEdit, copy the following line and paste it into the file:
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

reset Mac PATH via GUI

Hit Command + S to save the changes to the file and Command + W to close the file.

Successfully Resetting the PATH Variable on Mac

Modifying or setting the PATH environment variable on Mac isn’t easy if you don’t have prior experience and puts you at risk of breaking the terminal functionality with incorrect modification (delete/add/edit) of the entries in the PATH configuration files.

So if/when you end up in such a situation on your Mac, you should be able to reset the PATH environment variable using this guide. And subsequently, restore the terminal’s functionality and re-address the paths to the programs/bash scripts you want to launch from anywhere on the file system.

FAQs About Resetting PATH Variable on Mac

1. How do I reset my PATH variable?

Resetting the PATH variable is possible either via the CLI or the GUI approach. So depending on your preference, you can pick either method to carry out the same. Follow the steps earlier in the post to find out the steps for both these methods.

2. What is the default PATH variable in Mac?

Ideally, the shell config or profile files comprise the following as the default PATH variable in Mac: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin, to allow you to execute various programs or commands in the terminal without specifying their absolute paths.

3. How do I fix my PATH environment variable?

In the event that you accidentally messed up your Mac’s PATH environment variable entries, you can fix them by adding the default PATH entries to your shell configuration file. Depending on how you like to perform operations on your Mac, you can either do this using the GUI (Finder) or CLI (terminal) approach.

4. PATH variable keeps resetting Mac?

If the PATH variable keeps resetting on your Mac, it could be because it isn’t permanently set. And so, you must edit your system’s default shell config file and add the default paths along with the path for the program/script you intend you want to be accessible globally to it.

Weekly Newsletter

Sign up for a specially curated Tech Newsletter.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. When did the default macOS paths change from:

    /usr/bin
    /bin
    /usr/sbin
    /sbin

    to:

    /usr/local/bin
    /usr/bin
    /bin
    /usr/sbin
    /sbin

    Some time ago we had to add /usr/local/bin to our path and now it seems Apple is putting our personal binaries ahead of its own by default. Why the change?