146

Hello I am following this page.. I'm installing Python onto my mac so that I can set up a Django / Eclipse development environment. However I am not too sure how to go about executing this step:

  • The script will explain what changes it will make and prompt you before the installation begins.
  • Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable.
  • You can do this by adding the following line at the bottom of your ~/.bashrc file
  • export PATH=/usr/local/bin:$PATH

Where do I find the bashrc file on my mac and where do I find the homebrew directory?

I am running a macbook pro with OS 10.8.5.

5
  • 4
    find / -name \*bashrc\*. Plus, it tells you exactly where: ~/.bashrc, where ~ is Unix short-hand for "user's home directory".
    – Marc B
    Commented Oct 29, 2013 at 15:37
  • 1
    In ~/.bashrc. ~ is an abbreviation for your homedir that the shell understands.
    – Fred Foo
    Commented Oct 29, 2013 at 15:37
  • 5
    If you don't have .bashrc in your homedir you have to create it yourself :)
    – furas
    Commented Oct 29, 2013 at 15:46
  • 8
    i dont think this was off topic and am glad i found it here Commented Oct 14, 2016 at 21:01
  • As the question is about setting up development tools (python) it's on-topic for Stack Overflow.
    – Cirdec
    Commented May 16, 2017 at 21:40

10 Answers 10

136

The .bashrc file is in your home directory.

So from command line do:

cd
ls -a

This will show all the hidden files in your home directory. "cd" will get you home and ls -a will "list all".

In general when you see ~/ the tilda slash refers to your home directory. So ~/.bashrc is your home directory with the .bashrc file.

And the standard path to homebrew is in /usr/local/ so if you:

cd /usr/local
ls | grep -i homebrew

you should see the homebrew directory (/usr/local/homebrew). Source

Yes sometimes you may have to create this file and the typical format of a .bashrc file is:

# .bashrc

# User specific aliases and functions
. .alias
alias ducks='du -cks * | sort -rn | head -15'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

PATH=$PATH:/home/username/bin:/usr/local/homebrew
export PATH

If you create your own .bashrc file make sure that the following line is in your ~/.bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
6
  • Thanks I tried ls ~/.bashrc but it says No such file or directory. Do I have to create it from scratch? Commented Oct 29, 2013 at 15:51
  • 7
    This answer helped me figure it out. and this comment will update the thread. I am on mac SierraOS found it '/etc/bashrc' ... the system wide bashrc was not hidden .bashrc. to manipulate it I had to 'sudo vi bashrc' to exit after editing: :wq! ... full command 'cd /etc/; sudo vi bashrc' Commented Feb 4, 2017 at 16:05
  • typically $PATH is at the end and customer directories at the start. That allows you to choose alternatives to system commands. PATH=/home/username/bin:/usr/local/homebrew:$PATH
    – null
    Commented Jul 17, 2019 at 11:19
  • Rather than /home/username perhaps use $HOME for a more flexible approach, so you don't need to change the username for a different user.
    – null
    Commented Jul 17, 2019 at 11:21
  • 2
    The other answer of just using .bash_profile is much quicker and simpler.
    – null
    Commented Jul 17, 2019 at 11:23
68

I would think you should add it to ~/.bash_profile instead of .bashrc, (creating .bash_profile if it doesn't exist.) Then you don't have to add the extra step of checking for ~/.bashrc in your .bash_profile

Are you comfortable working and editing in a terminal? Just in case, ~/ means your home directory, so if you open a new terminal window that is where you will be "located". And the dot at the front makes the file invisible to normal ls command, unless you put -a or specify the file name.

Check this answer for more detail.

4
  • I get the following Shajilhost:~ ShajilShocker$ sudo ~/.bash_profile Password: sudo: /Users/ShajilShocker/.bash_profile: command not found could you please help me
    – Shajo
    Commented Apr 26, 2015 at 10:24
  • You have to use some kind of editor like nano or open it on your desktop. So it would be nano ~/.bash_profile The sudo command just runs whatever command follows it as a superuser, so you were trying to use the file name as a command (which is why it says "command not found").
    – beroe
    Commented Apr 26, 2015 at 15:46
  • My intention is to create environment variable KEY is ANDROID_NDK_HOME and VALUE is /Users/ShajilShocker/Documents/Android/NDK/android-ndk-r10b ...so now I have to open the terminal and ` nano .bash_profile` and enter ANDROID_NDK_HOME="/Users/ShajilShocker/Documents/Android/NDK/android-ndk-r10b" am i correct ? or add the following line as well export PATH=$PATH:ANDROID_NDK_HOME correct me If I am wrong.
    – Shajo
    Commented Apr 26, 2015 at 18:51
  • I believe the first would be sufficient and correct, but haven't tried the Android SDK...
    – beroe
    Commented Apr 27, 2015 at 5:53
17

In my macOS Monterey version, zsh is the default terminal shell. zsh executes ~/.zshrc every time the terminal is opened.

vi ~/.zshrc
#Add your path export to .zshrc
PATH=/usr/local/bin:$PATH 

Now, when you open the terminal, the path will be set correctly.

1
  • 2
    This is the answer which worked for me in 2022 Commented Nov 2, 2022 at 13:14
16

On your Terminal:

  • Type cd ~/ to go to your home folder.

  • Type touch .bash_profile to create your new file.

  • Edit .bash_profile with your code editor (or you can just type open -e .bash_profile to open it in TextEdit).
  • Type . .bash_profile to reload .bash_profile and update any functions you add.
2
  • 2
    . . bash_profile didn't work for me, still got "no such file or directory: .bash_profile". then I did this source ~/.bash_profile and the .bash_profile was reloaded Commented Feb 28, 2021 at 15:04
  • This works fine, but then I have to do source ~/.bash_profile after each reboot. Any idea how to fix?
    – Sliq
    Commented Jul 6, 2021 at 7:11
7

On some system, instead of the .bashrc file, you can edit your profils' specific by editing:

sudo nano /etc/profile
0
5

The .bash_profile for macOS is found in the $HOME directory. You can create the file if it does not exit. Sublime Text 3 can help.

  • If you follow the instruction from OS X Command Line - Sublime Text to launch ST3 with subl then you can just do this

    $ subl ~/.bash_profile
    
  • An easier method is to use open

    $ open ~/.bash_profile -a "Sublime Text"
    

Use Command + Shift + . in Finder to view hidden files in your home directory.

3

~/.bashrc is already a path to .bashrc.

If you do echo ~ you'll see that it's a path to your home directory.

Homebrew directory is /usr/local/bin. Homebrew is installed inside it and everything installed by homebrew will be installed there.

For example, if you do brew install python Homebrew will put Python binary in /usr/local/bin.

Finally, to add Homebrew directory to your path you can run echo "export PATH=/usr/local/lib:$PATH" >> ~/.bashrc. It will create .bashrc file if it doesn't exist and then append the needed line to the end.

You can check the result by running tail ~/.bashrc.

2

Open Terminal and execute commands given below.

cd /etc
subl bashrc

subl denotes Sublime editor. You can replace subl with vi to open bashrc file in default editor. This will workout only if you have bashrc file, created earlier.

1

Go to home directory of your user: cd ~/ list all hidden files in the directory using: ls -a locate the file: .zprofile Edit the file in vi and enter your alias in it at the end of the file. Eg: alias ll='ls -lart' Save with: wq: Run the command: source .zprofile Run the command: ll. You will see the alias working.

0
  1. Go to home directory of your user: cd ~/
  2. list all hidden files in the directory and locate: .zprofile
  3. Edit the file in vi and enter your alias in it at the end of the file. Eg: alias ll='ls -lart'
  4. Save and exit the file.
  5. Run the command: source .zprofile
  6. Run the command: ll. You will see the alias working.
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 7, 2023 at 21:45

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