macOS Catalina 10.15(beta) - Why is ~/.bash_profile not sourced by my shell?

BashShellEnvironment VariablesZshMacos Catalina

Bash Problem Overview


I want to set the environment variable I added below the line to ~/.bash_profile and ~/.profile but it didn't work.

export JBOSS_HOME=/Users/{USERNAME}/Desktop/jboss7

Afterward, exit the terminal and open it again when executing echo $JBOSS_HOME I get nothing.
enter image description here

Bash Solutions


Solution 1 - Bash

Apple has changed the default shell to zsh. Therefore you have to rename your configuration files. .bashrc is now .zshrc and .bash_profile is now .zprofile.

Solution 2 - Bash

If you for some reason (as me) don't want to rename/move your ~/.bash_profile file you can do the next things:

  1. Create a new file ~/.zprofile
  2. Type there source ~/.bash_profile
  3. Save and close
  4. Run a new terminal session

Solution 3 - Bash

You can just copy your existing bash_profile and name it zprofile and it will work fine.

  • Run the below command in terminal and you are set after closing and opening new terminal.

cp ~/.bash_profile ~/.zprofile

Solution 4 - Bash

I created a new file called

/usr/local/bin/mybash

which contains a wrapper script:

/usr/local/bin/bash --init-file $HOME/.bashrc

I installed this local/bin/bash from HomeBrew.

Full Sequence of Events

brew install bash
echo "/usr/local/bin/bash --init-file $HOME/.bashrc" > /usr/local/bin/mybash
chmod +x /usr/local/bin/mybash

Then I opened the settings for terminal.app [cmd-comma]. Under the General Tab, select the radio button for Command (complete path)

In the text box change the text from /bin/zsh/ to /usr/local/bin/bash.

Example of final format

Solution 5 - Bash

After you close a Terminal window, variables you set in that window are no longer available. If you want the value of a variable to persist across sessions and in all Terminal windows, you must set it in a shell startup script. For information about modifying your zsh shell startup script to keep variables and other settings across multiple sessions, see the “Invocation” section of the zsh man page.

You can use ~/.zlogin to add your variables.

Check out this reference.

Solution 6 - Bash

changing the bash profile to zsh profile works and source it as well to see in action.

vikas@Vikas-Kumar ~ % mv .bash_profile .zsh_profile
vikas@Vikas-Kumar ~ % source .zsh_profile

Solution 7 - Bash

You can create a simbolic link and keep your .bash_profile file with this:

ln -s .bash_profile .zsh_profile
source .zsh_profile

Any changes in .bash_profile will be reflected in .zsh_profile

Solution 8 - Bash

you don't need to update the file, zsh is mac's default, put this in terminal. e.g.:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

Solution 9 - Bash

Even with os Catalina /bin/bash comes for free, brew is not needed. Simply create your .bash_profile and set shell in terminal settings to /bin/bash. it automatically finds your .bash_profile. z-shell is not bash-shell and simply renaming will work in most cases but definitely is not correct.

Solution 10 - Bash

cp zprofile ~/.zprofile

Add to .zprofile:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

eg. by >vi .zprofile

Done

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionReza DehnaviView Question on Stackoverflow
Solution 1 - Bashalexschu98View Answer on Stackoverflow
Solution 2 - BashRostyslav DruzhchenkoView Answer on Stackoverflow
Solution 3 - BashAmin AghaView Answer on Stackoverflow
Solution 4 - BashExoWandererView Answer on Stackoverflow
Solution 5 - Bashabhay anandView Answer on Stackoverflow
Solution 6 - Bashvikas kumarView Answer on Stackoverflow
Solution 7 - BashGilbertoView Answer on Stackoverflow
Solution 8 - BashgpbaculioView Answer on Stackoverflow
Solution 9 - BashPeter ÄtgugelView Answer on Stackoverflow
Solution 10 - BashMaggieView Answer on Stackoverflow