0

I have set following path in my bash_profile file:

export ANDROID_HOME=/Users/viki-donor/Library/Android/sdk
export PATH=$ANDROID_HOME/build-tools/26.0.2:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

I saved it and ran the command source ~/.bash_profile. If I type adb the command is running successfully. But after sometime. If I run the same command adb its not able to recognize the command and I get command not found error. I again run source ~/.bash_profile and it starts working fine. Why do I have to run source ~/.bash_profile again and again ?

6
  • 1
    I think that ~/.bash_profile is only run for login shells, you should add these settings to ~/.bashrc. Commented Apr 5, 2018 at 10:34
  • Added in that as well. I have kept in both the places bash_profile and bashrc_profile Same problem @ArkadiuszDrabczyk
    – sagar suri
    Commented Apr 5, 2018 at 10:39
  • Is the subsequent errors in the same shell instance that you sourced it earlier? If so, something else are messing with the environment, what does echo $PATH say when it is broken and what might set it to that value? Commented Apr 5, 2018 at 16:44
  • After adding the PATH to bash_profile I closed the terminal. I ran echo $PATH and its giving me correct value. But after sometime when I leave the system and open a new terminal instance I get command not found error. I have to source ~/.bash_profile again to get the PATH working fine. @GertvandenBerg
    – sagar suri
    Commented Apr 5, 2018 at 17:39
  • 1
    @XoXo: The bashrc file is ~/.bashrc NOT ~/.bashrc_profile see the FILES section in bash's man page Commented Apr 5, 2018 at 19:02

1 Answer 1

1

Note: This only applies if you are using bash as your shell. Other shells have other scripts.

To ensure that the settings are loaded in non-login shells, you should add it to the .bashrc file in your home directory.

(It often makes sense to have this in your .bash_profile):

[[ -f ~/.bashrc ]] && . ~/.bashrc

This means that your bashrc is always loaded, whether it is a login shell or not.

For settings that should apply to all users, you can usually create a .sh file in /etc/profile.d/ with the settings or edit /etc/bashrc (or /etc/bash.bashrc in some cases) (and /etc/profile)

(There are often better methods to set environment variables, like /etc/environment on Linux boxes using pam_env)

1
  • great answer. Thanks
    – sagar suri
    Commented Apr 7, 2018 at 1:59

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