How to restore .bash_profile on a mac? None of my unix terminal are working

57,593

While this is offtopic for stackoverflow, it's also pretty simple to fix:

  1. Start Terminal.app.
  2. Reset $PATH:

    $ export PATH=/bin:/usr/bin:/usr/local/bin
    
  3. Fix ~/.bash_profile:

    $ vi ~/.bash_profile
    

Or you can avoid setting $PATH at all with:

$ /usr/bin/vi ~/.bash_profile
Share:
57,593

Related videos on Youtube

j.jerrod.taylor
Author by

j.jerrod.taylor

I like to travel I speak Spanish and Portuguese I have an interest in machine learning and nlp

Updated on January 12, 2020

Comments

  • j.jerrod.taylor
    j.jerrod.taylor over 4 years

    I added something to my bash_profile while trying to add Playframework to my path and something got messed up badly.

    I added the following line to my .bash_profile

    export PATH=$PATH:the path to my play excitable 
    

    then I saved everything and restarted my terminal. I can no longer do anything from my terminal. I can't cd into any directory, I can no longer find java, I can't open vi or nano. I found this thread on SuperUser that suggested opening a different terminal and changing the bash profile.

    I tried opening bash by typing

    /bin/bash
    

    and I was successfully able to open another terminal but I still don't have access to any of the regular unix commands. I still wasn't able to open vi or nano to remove the line that is causing the problem.

    I tried downloading a new terminal application without any luck.

    I tried turning on hidden files so that I can just change the file with a text editor by running the following command:

    defaults write com.apple.finder AppleShowAllFiles TRUE
    

    but since my terminal isn't working that didn't work either.

    How can I fix my computer.

    • j.jerrod.taylor
      j.jerrod.taylor over 10 years
      @MarcB Can this be migrated to a different stackexchage site?
    • damienfrancois
      damienfrancois over 10 years
      Did you create ` .bash_profile` or was it pre-existing? Do you have a .profile file ? If so, merge them (use Finder).
    • tripleee
      tripleee over 10 years
      "Can't cd" sounds like you messed up more than you are telling us. But if it's just the PATH after all, you should be able to use a full path; /usr/bin/vi (or wherever is correct for your platform; /bin/vi? /Applications/Visual Editor.app?)
    • j.jerrod.taylor
      j.jerrod.taylor over 10 years
      @damienfrancois I tried that and it didn't seem to work. I took a screenshot of my terminal. Here is the picture.
    • damienfrancois
      damienfrancois over 10 years
      try /usr/bin/vi ~/.bash_profile as @trojanfoe suggests
    • tripleee
      tripleee almost 4 years
      The duplicate stackoverflow.com/questions/29246238/… has some less Mac-specific advice.
  • trojanfoe
    trojanfoe over 10 years
    @damienfrancois My solution is to set $PATH temporarily, just long enough to find vi. I am not suggesting what his final $PATH should be set to in .bash_profile. And vi is in /usr/bin.
  • damienfrancois
    damienfrancois over 10 years
    @trojanfoe vi is located in /opt/usr/bin. Please read my previous comments
  • l'L'l
    l'L'l over 10 years
    @damienfrancois, the vi you are suggesting is the macports version. it's presumed most people would use the one at /usr/bin/vi
  • j.jerrod.taylor
    j.jerrod.taylor over 10 years
    I tried that and it didn't seem to work. I took a screenshot of my terminal. Here is a the picture. It is hosted on imgur.
  • j.jerrod.taylor
    j.jerrod.taylor over 10 years
    @trojanfoe I figured out what you meant. When you wrote "usr" I thought you were just using an abbreviation for username. I was using my actual username instead of the string "usr" I was able to open it. Thanks.
  • damienfrancois
    damienfrancois over 10 years
    @j.jerrod.taylor usr is not your username, it is the three letters usr as is.
  • tripleee
    tripleee almost 4 years
    If you don't know how to edit your shell's startup files, chances are you also don't know how to exit vi, let alone use it for editing. The editor nano is obnoxious, too, but reportedly easier for beginners to cope with. Whether nano is installed by default obviously depends on your distro, but most of them seem to install it just because it has become the de facto standard for what to recommend to people who have no idea about editors. It is also installed by default on macOS (at least, I have it in /usr/bin/nano.)