Shell Startup File
env.sh
- The
env.sh
is a config file to seperate aliases, exports, path, etc from the shell startup files. - It is aim to not pollute the
~/.bashrc
or~/.zshrc
too much. - Create
$HOME/env.sh
using your favorite text editor:
# Java
export JAVA_HOME="`/usr/libexec/java_home -v 1.8`"
# Node Version Manager
export NVM_DIR="$HOME/.nvm"
. "/usr/local/opt/nvm/nvm.sh"
nvm use 6.9.2
# Ruby rbenv
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
# For long shell history
if [[ $SHELL == '/usr/local/bin/zsh' ]]; then
HIST_STAMPS="yyyy-mm-dd"
HISTSIZE=2147483647
SAVEHIST=2147483647
alias history='fc -il 1'
else
export PROMPT_COMMAND='history -a'
export HISTTIMEFORMAT="%Y-%m-%d %T "
export HISTFILESIZE=2147483647
export HISTSIZE=2147483647
fi
# For Google Cloud SDK
if [[ $SHELL == '/usr/local/bin/zsh' ]]; then
# The next line updates PATH for the Google Cloud SDK.
if [ -f $HOME/google-cloud-sdk/path.zsh.inc ]; then
source $HOME/google-cloud-sdk/path.zsh.inc
fi
# The next line enables shell command completion for gcloud.
if [ -f $HOME/google-cloud-sdk/completion.zsh.inc ]; then
source $HOME/google-cloud-sdk/completion.zsh.inc
fi
else
# The next line updates PATH for the Google Cloud SDK.
if [ -f $HOME/google-cloud-sdk/path.bash.inc ]; then
source $HOME/google-cloud-sdk/path.bash.inc
fi
# The next line enables shell command completion for gcloud.
if [ -f $HOME/google-cloud-sdk/completion.bash.inc ]; then
source $HOME/google-cloud-sdk/completion.bash.inc
fi
fi
Note: For JAVA_HOME, change the version based on your Java version.
Note: For Node Version Manager, change the version based on your Node.js version that you use most of the time.
- Then edit your
~/.bashrc
and~/.zshrc
(if you are using Zsh) and appened the followings:if [ -f $HOME/env.sh ]; then source $HOME/env.sh fi
Bash Startup files
If you are using the default Bash Shell, create
~/.bash_profile
if it does not exist.Then edit your
~/.bash_profile
and append the followings:if [ -f $HOME/.bashrc ]; then source $HOME/.bashrc fi
To check, open a new terminal tab by pressing keys
Cmd+T
, then type:echo $PATH
You should able to see the output like this:
/Users/sierra/.rbenv/shims:/Users/sierra/.nvm/versions/node/v6.9.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
If you see the output like this instead:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Either
env.sh
or.bashrc
is not loaded properly.