How to run ~ / .bash_profile file in mac terminal

So, I install some things for coding and personal use, and I need to run this in the terminal (I am on a Mac if you have not read the name).

~/.bash_profile

It just says permission is denied, Im running OSX 10.8.4 Mountain Lion. How to get around this?

+23
terminal macos
source share
6 answers

You will never want to run this, but you may want to download it.

 . ~/.bash_profile source ~/.bash_profile 

both should work. But this is an odd request, because this file should be sent automatically when bash starts, unless you explicitly run it non-interactively. On 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 / etc / profile file, if that file exists. After reading this file, it searches 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 can be used when the shell begins to block this behavior.

+29
source share

MacOS: add source .bash_profile to the end of ~/.zshrc . Then this profile will act when you open zsh.

+8
source share

If you change .bash_profile, it will only apply to new terminal sessions.

To apply it to an existing session, run source ~/.bash_profile . In this way, you can run any Bash script - think of executing source in the same way as a set of commands in a terminal window (from the specified script).

More: How to reload .bash_profile from the command line?

Bonus: you can make environment variables available for OSX applications - not only for the current Bash session, but also for applications such as Visual Studio Code or IntelliJ - using launchctl setenv GOPATH "${GOPATH:-}"

+7
source share

As @kojiro said, you don’t want to “run” this file. Source, as he says. It should get the "source" at startup. Sourcing simply means running every line in the file, including the one you want to run. If you want to make sure that the folder is in a certain environment variable of the path (as you think, from one of the comments to another solution), do

 $ echo $PATH 

At the command line. If you want to verify that your ~ / .bash_profile file is in its original state, either at startup, as it should be, or when you manually download it, enter the following line in the ~ / .bash_profile file:

 $ echo "Hello I'm running stuff in the ~/.bash_profile!" 
+1
source share

No need to run, it will automatically run when your mac / bash terminal starts. Whenever you make changes, you may need to restart the terminal.

~ - default path for .bash_profile

+1
source share

If the problem is that you don’t see that your changes to the file have taken effect, simply open a new terminal window and it will be “received”. You can use the appropriate PATH, etc. With each subsequent window of the terminal.

0
source share

All Articles