149

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

5
  • I guess .bash_profile has not been sourced. Are you sure that your terminal creates a bash login shell? If not, .bash_profile would be ignored. Jun 27, 2019 at 9:55
  • 1
    @user1934428 Yes that's right.I don't know why the default bash is changed?!! Jun 27, 2019 at 12:24
  • I don't get it. What "default" is changed? You did not say, which Terminal program you are using, but ususally you can configure the Terminal application how to start the shell. Jun 28, 2019 at 5:01
  • @user1934428 I didn't know there is the various shell. Jun 28, 2019 at 12:37
  • 1
    Apple replaces bash with zsh as the default shell in macOS Catalina stackoverflow.com/a/59151321/5788247
    – Shomu
    Feb 24, 2020 at 11:37

10 Answers 10

376

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.

5
  • 4
    Apple changed from bash to zshell due to licensing concerns. thenextweb.com/dd/2019/06/04/… Oct 18, 2019 at 13:22
  • 174
    It's such an awesome user experience how my dev setup breaks with every OS-X upgrade Oct 24, 2019 at 22:41
  • 2
    @ChrisHatton I just keep waiting for the next update so that I can break my current setup and start everything from scratch nonce again, looking forward for the next release! Jun 4, 2020 at 8:51
  • I'm using bash, .bashrc is loaded but bash_profile is not. I ended up adding [ -f ~/.bash_profile ] && source ~/.bash_profile to .bashrc and deleting a chunk, generated by conda init bash, in .bash_profile that source .bashrc. Is it just me having the same problem?
    – Tianyi Shi
    Apr 7, 2021 at 23:05
  • I was searching for this all over internet. This worked for me. Thankyou. Aug 27, 2021 at 5:51
68

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
7

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

1
  • Be aware that if you've, e.g., run Brew since the change to zsh you may have content in that .zprofile that you want to keep. Better to concatenate the two than ovewrite.
    – brianfit
    Aug 7, 2022 at 13:11
5

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

1
  • 2
    This is a good option, as the above answers do not take into consideration that certain syntax are different in zsh and bash. Mar 11, 2020 at 11:47
3

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.

1

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
1

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

1
  • I am getting ln: .zsh_profile: Operation not permitted Oct 22, 2020 at 11:17
1

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.

1
  • This answer did the trick for me by switching from /bin/zsh to /bin/bash in the terminal setting. Apple's article gave me the why: support.apple.com/en-us/HT208050. I think staying with bash on machines utilized for software development makes sense for max compatibility with console based dev-tools.
    – benhorgen
    Jun 2, 2022 at 17:25
0

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
-3
cp zprofile ~/.zprofile

Add to .zprofile:

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

eg. by >vi .zprofile

Done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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