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

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
Reza Dehnavi
  • 2,256
  • 3
  • 16
  • 30
  • 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. – user1934428 Jun 27 '19 at 09:55
  • 1
    @user1934428 Yes that's right.I don't know why the default bash is changed?!! – Reza Dehnavi Jun 27 '19 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. – user1934428 Jun 28 '19 at 05:01
  • @user1934428 I didn't know there is the various shell. – Reza Dehnavi Jun 28 '19 at 12:37
  • 1
    Apple replaces bash with zsh as the default shell in macOS Catalina https://stackoverflow.com/a/59151321/5788247 – Shomu Feb 24 '20 at 11:37

10 Answers10

377

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.

alexschu98
  • 3,920
  • 1
  • 9
  • 14
  • 4
    Apple changed from bash to zshell due to licensing concerns. https://thenextweb.com/dd/2019/06/04/why-does-macos-catalina-use-zsh-instead-of-bash-licensing/ – Manuel Hernandez Oct 18 '19 at 13:22
  • 175
    It's such an awesome user experience how my dev setup breaks with every OS-X upgrade – Chris Hatton Oct 24 '19 at 22:41
  • 3
    @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! – Utsav Gupta Jun 04 '20 at 08: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 07 '21 at 23:05
  • I was searching for this all over internet. This worked for me. Thankyou. – Pranali Rasal Aug 27 '21 at 05: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
Rostyslav Druzhchenko
  • 3,673
  • 3
  • 33
  • 38
8

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

Amin Agha
  • 341
  • 4
  • 11
  • 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 07 '22 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

ExoWanderer
  • 74
  • 2
  • 5
  • 2
    This is a good option, as the above answers do not take into consideration that certain syntax are different in zsh and bash. – Prashant Sharma Mar 11 '20 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.

alan.elkin
  • 954
  • 1
  • 10
  • 19
abhay anand
  • 323
  • 3
  • 7
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
vikas kumar
  • 10,447
  • 2
  • 46
  • 52
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

Gilberto
  • 35
  • 3
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.

YLR
  • 1,503
  • 4
  • 21
  • 28
  • 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: https://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 02 '22 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
gpbaculio
  • 5,693
  • 13
  • 60
  • 102
-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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Maggie
  • 1