I was installing ruby on rails along with homebrew the other day and was following a step by step list of what to do. I now have this bash syntax error every time I enter the terminal:

-bash: /Users/briggsmcknight/.bash_profile: line 6: syntax error near unexpected token `source'
-bash: /Users/briggsmcknight/.bash_profile: line 6: `if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi source /Users/briggsmcknight/.bash_profile'

Could I get a small step by step breakdown of what I should do to fix this? I believe the syntax error is by "fi" or "source", but do I just retype it again or what?

  • Can You paste first 7 lines of your .bash_profile file? Commented Dec 8, 2016 at 19:58
  • @MateuszSzlosek He can't as he can't get a command line prompt
    – mmmmmm
    Commented Dec 8, 2016 at 20:17
  • @BriggsMcnight do you end up with a prompt in the terminal or does the shell exit?
    – mmmmmm
    Commented Dec 8, 2016 at 20:18
  • He can open it via TextEdit.app (If file is hidden, there's a shortcut to see it Open File dialog: CMD+SHIFT+. <dot> ) Commented Dec 8, 2016 at 20:19
  • @MateuszSzlosek I had forgotten the key shortcut
    – mmmmmm
    Commented Dec 8, 2016 at 20:43

3 Answers 3


The simplest step might be to move the hidden file to your desktop and start over making that file.

If you're OK editing the file - perhaps using nano - you can delete the line 6 or comment it out by putting a # before the first character on that line and saving the file.

/usr/sbin/nano ~/.bash_profile

To just start over and get a working terminal:

/bin/mv ~/.bash_profile ~/Desktop/bash_profile.txt
  • How do you move the file? It is probably hidden and so not visible in Finder
    – mmmmmm
    Commented Dec 8, 2016 at 20:12
  • @Mark yup - that's why the mv command to remove the leading . ; - ) Also - you still get a prompt when there's an error in the startup shells. Just type the letters above (mv is best to do first if you're not sure if you can edit it in shape) and then open a new terminal to test your work.
    – bmike
    Commented Dec 8, 2016 at 20:24
  • 1
    Awesome it worked! Much appreciated bmike. Commented Dec 9, 2016 at 23:06

Edit the file with a GUI program e.g. TextEdit

Open TextEdit and select the home directory. .bash_profile is hidden so instead of a simple selection then you might have to hit CmdShift. to show .bash_profile When saving delete the .txt ending TextEdit adds or alter TextEdits's preferences.


Edit the file with a GUI app like TextEdit or TextWrangler - I recommend the latter.

Open the invisible file .bash_profile in your home folder either with TextEdit by hitting CmdShift. or with TextWrangler by checking the button "Show hidden items" in the open dialog.

Remove all if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi source /Users/briggsmcknight/.bash_profile related lines and only leave eval "$(rbenv init -)" and your other mods in the file.

Save the file as .bash_profile (without any suffix like txt or rtf).

Relaunch Terminal.

You mustn't source .bash_profile in the file .bash_profile itself (without a proper if/then/else statement) because you will either get an error or a loop.


Not the answer you're looking for? Browse other questions tagged .