iTerm/zsh not reading .bashrc OR .bash_profile

78,654

Solution 1

The answer is simple, almost evident in the question. Here's why:

The shell zsh is not bash, it is a different shell. zsh will not use the default files built for bash: .bashrc or .bash_profile. These two files are startup configuration files for bash. zsh has its own startup configuration files.

You can find out more about them here on the zsh intro page:

There are five startup files that zsh will read commands from:

$ZDOTDIR/.zshenv
$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout

You had mentioned your aliases don't work, to fix this, apply your aliases here like so:

~/.zshrc

alias sz='source ~/.zshrc'     # Easily source your ~/.zshrc file.
alias ls='pwd; ls --color'     # Alias 'ls' to: pwd + ls + color.

Solution 2

If you are using zsh then to force source .bash_profile

in ~/.zshrc add the line below

source ~/.bash_profile

P.S - I havent investigated whether this can cause any problem.

Solution 3

Copy the lines from ~/.bash_profile to ~/.zshrc

cat ~/.bash_profile >> ~/.zshrc

And open a new terminal tab/window or use source ~/.zshrc

Share:
78,654

Related videos on Youtube

Damon
Author by

Damon

Updated on September 18, 2022

Comments

  • Damon
    Damon over 1 year

    In ~/.bash_profile I have :

    if [ -f ~/.bashrc ]; then
        source ~/.bashrc
    fi
    

    In ~/.bashrc I have some aliases

    When I load a new iTerm window, my aliases do not work. If I source ~/.bashrc they work. If I source ~.bash_profile they work.

    Isn't at least one of these supposed to be sourced automatically?

    What might be causing it not to work properly?

  • Bradley Flood
    Bradley Flood almost 9 years
    Thank you. Note that ls --color gave me illegal option in both bash and zsh on OSX 10.10, but not on Linux -- I'll look into it. Cheers.
  • p̻̻̥r̥̻̥o̻j̤͛ec͔t̞dp
    p̻̻̥r̥̻̥o̻j̤͛ec͔t̞dp almost 9 years
    I don't have a Mac to test on but I think this has to do with the ls implementation on OS X, I don't think it has the - -color argument. If I remember I'll look it up.
  • eyurdakul
    eyurdakul over 5 years
    "... zsh has its own startup configuration files." this is what he probably asks for huh? just say "dude, it is ~/.zshrc".
  • Oleksii Kyslytsyn
    Oleksii Kyslytsyn over 4 years
    I guess this answer would be helpful after release of macOS 10.5 Catalina in order to port bash_profile from bash to zsh.
  • Roberto Manfreda
    Roberto Manfreda over 4 years
    Fast and effective!
  • therobyouknow
    therobyouknow over 4 years
    +1 great tips in the answer for macOS Catalina now using zsh officially. Thank you.
  • cgnorthcutt
    cgnorthcutt about 4 years
    Note this is very bad idea if your .bash_profile calls source .bashrc. Then you'll have a zsh shell loading a bunch of bash code and probably do weird behavior.
  • James Koss
    James Koss about 4 years
    @cgnorthcutt Why is loading bash code a problem? If it's just setting up some simple aliases, for example.
  • cgnorthcutt
    cgnorthcutt about 4 years
    @JamesKoss Say the next day you install a program that modifies your .bashrc to loop over a bunch of other aliases to add. Oops... zsh and bash use different looping indices, and now your .zshrc is broken.
  • Gerard Reches
    Gerard Reches about 4 years
    This deleted all my ~/.zshrc previous contents.
  • I Don't Exist
    I Don't Exist about 4 years
    @GerardReches Sorry for the mess. In my case, I didn't have ~/.zshrc so > will create and add the lines from ~/.bash_profile. you should have used >> update operator to append `~/.zshrc.
  • jonny
    jonny about 3 years
    For macOS, use ls -G insted of ls --color