Sign up ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

This question already has an answer here:

I recently tried to install CoffeeScript on my mac and now am unable to use even the most basic of commands like ls, cd and so on. Something tells me that it's because the $PATH variable has changed. I remember having to do that when I tried to make the installation. I tried following the instructions found here, but it doesn't work because the vi command isn't found.

Upon entering echo $PATH in the terminal, it reads /usr/local/bin:

share|improve this question

marked as duplicate by bmike Oct 19 at 17:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

cd is a shell built-in. Nothing you do to $PATH should be able to break it, so quite possibly you've done something much worse to your machine. – Wooble Apr 24 '14 at 17:01
It is odd that echo works but cd and ls do not. Try opening Terminal preferences and making a new profile. Then make it run bash --noprofile and uncheck "Run in shell" (I think the options for this are in the Advanced tab). Also see if type or which work. – 0942v8653 Apr 24 '14 at 22:05
To add to the @Wooble correct analysis, I think that cd is working and you thought it didn't because of ls not usable. I advise you to double check this information and upgrade your original question to avoid people wanting to help you to hunt for a martian :). – daniel Azuelos Oct 8 at 21:09

3 Answers 3

To reset your path, remove the line that sets the path from your ~/.bash_profile or equivalent, then reopen your Terminal.

Edit it with /usr/bin/nano, or /usr/bin/open, or TextMate, or any other text editor. It's not that no command can be reached, but that the PATH doesn't include these binaries—they can still be manually opened by providing the path or using cd to the directory.

share|improve this answer
Also, you can the path temporarily to test things before editing files that don't get read until you start a new session - – bmike Oct 19 at 15:36

It sounds like you removed or didn't configure your PATH environment variable correctly. Try removing that line from ~/.bash_profile then open a new terminal window and verify that your paths are set correctly.

You don't have to use a command line text editor, you can use BareBones Software's excellent and free TextWrangler. This should reduce errors trying to figure out how vi works.

If you do not want to install another app, vi is located at /usr/bin/vi. For command line editors I would recommend pico over vi /usr/bin/pico which is much more user friendly than vi or emacs, but is clunky when compared to TextWrangler. Pico puts all of the relevant commands at the bottom of the editing window.

Good Luck!

share|improve this answer
You can use which is part of OSX no need for TextWramgler – Mark May 6 '14 at 22:53

You corrupted your PATH variable definition. Without any indication of which method you choosed to modify it, I will make the hypothesis that you modified it within your ~/.bash_profile.

To recover from this situation, you will have to come back to a working shell environment and then try to fix correctly and test your ~/.bash_profile.

Recovery of a working ~/.bash_profile: none

Remove your ~/.bash_profile and create a backup of it. Since your PATH is not trustable, don't use it (use the full path of mv):

/bin/mv ~/.bash_profile ~/.bash_profile.bak

Open a new Terminal window, within this one, every command should be found. Check that you recovered a working PATH:

echo $PATH

If you find it easier, after this check, you could restart your session so that any new shell will get a working PATH.

Analyze what is wrong in your ~/.bash_profile

grep PATH ~/.bash_profile.bak

Fix and test it

Rather to fall back again with an unfunctionnal PATH, use the backup file of your ~/.bash_profile to fix it there it and test it.

To test it enter: . ~/.bash_profile.bak echo $PATH

Put back in place the validated /.bash_profile

Once you are satisfied, and you checked you have access to all your commands:

mv ~/.bash_profile.bak ~/.bash_profile

and if you want to use it immediatly without restarting your full session, just enter:

. ~/.bash_profile
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.