How to run ~/.bash_profile in mac terminal

Multi tool use
How to run ~/.bash_profile in mac terminal
So I'm installing some things for coding and personal usage, and I need to run this in the terminal (I'm on Mac if you didn't read the title).
~/.bash_profile
~/.bash_profile
It just says permission denied, Im running OSX 10.8.4 Mountain Lion. How do I bypass this?
looks like he's trying to set up python environment variables.
– Мати Тернер
Sep 16 '13 at 2:01
6 Answers
6
You would never want to run that, but you may want to source it.
. ~/.bash_profile
source ~/.bash_profile
both should work. But this is an odd request, because that file should be sourced automatically when you start bash, unless you're explicitly starting it non-interactively. From the man page:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
Good answer. But there is one time you might want to source: if you've just created it, and you want it to apply to the current session. Which sounds like exactly the OP's case. (That being said, anyone who doesn't already know the difference between
~/.bash_profile
and . ~/.bash_profile
is a lot better off just creating a new session—e.g., New Tab in Terminal.app, then close the old one.)– abarnert
Sep 16 '13 at 5:16
~/.bash_profile
. ~/.bash_profile
You can reload it with source .bash_profile
. This is useful if you've just edited it and want to apply the changes to a Terminal session that was already open.
source .bash_profile
More info: How to reload .bash_profile from the command line?
it worked for me thanks , i just entered the cmd source .bash_profile from my home directory where i created this .bash_profile
– Bravo
Jan 12 '17 at 7:37
No need to start, it would automatically executed while you startup your mac terminal / bash. Whenever you do a change, you may need to restart the terminal.
~ is the default path for .bash_profile
.bash_profile
As @kojiro said, you don't want to "run" this file. Source it as he says. It should get "sourced" at startup. Sourcing just means running every line in the file, including the one you want to get run. If you want to make sure a folder is in a certain path environment variable (as it seems you want from one of your comments on another solution), execute
$ echo $PATH
At the command line. If you want to check that your ~/.bash_profile is being sourced, either at startup as it should be, or when you source it manually, enter the following line into your ~/.bash_profile file:
$ echo "Hello I'm running stuff in the ~/.bash_profile!"
MacOS: Add source .bash_profile
to the end of ~/.zshrc
.
Then this profile will be effect when you open zsh.
source .bash_profile
~/.zshrc
If the problem is that you are not seeing your changes to the file take effect, just open a new terminal window, and it will be "sourced". You will be able to use the proper PATH etc with each subsequent terminal window.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You have python tagged, which is inappropriate. I'd like to make sure you aren't putting python in the file before removing the tag without comment?
– Tom Kerr
Sep 16 '13 at 1:15