How to make zsh run as a login shell on Mac OS X (in iTerm)?

150,695

Solution 1

In iTerm -> Preferences -> Profiles Tab -> General section set Command to: /bin/zsh --login

/bin/zsh --login

Solution 2

chsh -s $(which zsh)

You'll be prompted for your password, but once you update your settings any new iTerm/Terminal sessions you start on that machine will default to zsh.

Solution 3

Go to the Users & Groups pane of the System Preferences -> Select the User -> Click the lock to make changes (bottom left corner) -> right click the current user select Advanced options... -> Select the Login Shell: /bin/zsh and OK

Solution 4

The command to change the shell at startup is chsh -s <path_to_shell>. The default shells in mac OS X are installed inside the bin directory so if you want to change to the default zsh then you would use the following

chsh -s /bin/zsh

If you're using different version of zsh then you might have to add that version to /etc/shells to avoid the nonstandard shell message. For example if you want home-brew's version of zsh then you have to add /usr/local/bin/zsh to the aforementioned file which you can do in one command sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells" and then run

chsh -s /usr/local/bin/zsh

Or if you want to do the whole thing in one command just copy and paste this if you have zsh already installed

sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells" && chsh -s /usr/local/bin/zsh

Solution 5

Have you tried editing the shell entry in account settings.

Go to the Accounts preferences, unlock, and right-click on your user account for the Advanced Settings dialog. Your shell should be /bin/zsh, and you can edit that invocation appropriately (i.e. add the --login argument).

Share:
150,695

Related videos on Youtube

Ivan Tarasov
Author by

Ivan Tarasov

I work at Google on Cloud Dataflow (tag: [google-cloud-dataflow]). #SOreadytohelp

Updated on March 27, 2020

Comments

  • Ivan Tarasov
    Ivan Tarasov about 4 years

    When zsh is set as a login shell on Mac OS X, when it is started by iTerm, zsh doesn't consider that it's being run as a login shell, although it's started as ‘-zsh’ (‘-’ is put as the first character of arg[0]) which is supposed to mean that it should start as a login shell.

    So, when I set the login shell to bash, bash recognizes this first ‘-’ in $0 and runs as a login shell, but zsh doesn't, although it seems that it should.

    Is there a way to either make zsh recognize the ‘-’ in the arg[0], or make iTerm run the shell with a --login command line argument?

    • Craig S. Cottingham
      Craig S. Cottingham over 4 years
      I know it's been a while since this was asked, but please consider accepting @Harold Putman's answer. It's the only on which addresses the question asked.
  • Ivan Tarasov
    Ivan Tarasov over 14 years
    Unfortunately, that doesn't work: I can set whichever shell I like using chsh (as long as I have this shell listed in /etc/shells), however one cannot add command line arguments to the shell the Advanced preferences dialog (iTerm fails to start the shell up).
  • Ivan Tarasov
    Ivan Tarasov over 14 years
    Please, read the question first. The problem is not in setting the default shell, the problem is that zsh isn't detecting that it is started as a login shell.
  • Damien Wilson
    Damien Wilson over 14 years
    Ah, my apologies. Have you tried using the -i flag to force zsh to start in interactive mode?
  • iconoclast
    iconoclast about 13 years
    His answer does make zsh run as a login shell on Mac OS X in iTerm. It just doesn't go about doing it the way you describe trying to. But it solves the problem that you question (in the title, rather than in the body) presents. The question you end with in the body is a completely different question. If that's your real question (rather than how to make zsh run as login shell) then perhaps you should reword the question in the title.
  • engineerDave
    engineerDave almost 12 years
    Some of the syntax has changed in OS X but the gist is to set your default shell to be /bin/zsh as Brian indicates above
  • Brian Agnew
    Brian Agnew almost 11 years
    I love SO. I've used this answer just now, and only then realised I wrote it nearly 4 years ago!
  • Miroslav Nedyalkov
    Miroslav Nedyalkov over 10 years
    You may not have enough rights to execute this command. This is actually not needed as you can configure iTerm to run zsh instead of bash (like Harold suggested).
  • Lloyd Dewolf
    Lloyd Dewolf about 10 years
    iterm2 doesn't seem to have this option in the General tab. Any idea how to achieve in iterm2 without changing login shell?
  • Harold Putman
    Harold Putman about 10 years
    It's general tab on the Profiles Tab.
  • Lloyd Dewolf
    Lloyd Dewolf about 10 years
    Aha! That's confusing that there is both a General Tab and a Profiles > General.
  • qed
    qed almost 10 years
    This saved my day. I am on osx mavericks.
  • shovavnik
    shovavnik over 9 years
    If chsh tells you something like "nonstandard shell", it means you have to add the path of the new shell to /etc/shells. This can happen if you're changing, for example, to a version of zsh installed by homebrew, which puts it in /usr/local/bin/zsh.
  • Daniel Doezema
    Daniel Doezema over 9 years
    chsh -s $(which zsh) can be used to ensure correct path.
  • zx1986
    zx1986 almost 9 years
    I got chsh: /usr/local/bin/zsh: non-standard shell
  • Yar
    Yar almost 8 years
    or in my case /usr/local/bin/zsh --login
  • Hounaida
    Hounaida over 7 years
    I don't think it was fair to downvote this answer. Props as it is the only one that mentions /etc/shells in the body of the answer itself.
  • Autodidact
    Autodidact over 7 years
    Also works on my newly installed macOS, exactly i was looking for. My I've installed iTerm 2 v 3.0.10 via brew casking, does it make any difference?
  • Damien Wilson
    Damien Wilson over 7 years
    @Millisami Shouldn't matter. chsh is part of the FreeBSD distro that MacOS is based off of. This sets your default shell at a system level, so it'll cover iTerm, the default terminal, or any other terminal you have that respects the $SHELL environment variable.
  • sal
    sal about 7 years
    I'm using this to change my shell rather than edit the /etc/shells since this should prevent an issue with my shell becoming unusable after an update.
  • Imam Bux
    Imam Bux over 5 years
    This works for the default zsh not for the one installed by brew.
  • Tabitha
    Tabitha almost 5 years
    This is 100% not an answer. Yes chsh will change which shell you spawn by default, but that isn't an answer as to how to create a "login" instance of a shell, i.e. resource all variables from scratch.
  • Tabitha
    Tabitha almost 5 years
    This is 100% not an answer. Yes will change which shell you spawn by default, but that isn't an answer as to how to create a "login" instance of a shell, i.e. resource all variables from scratch.
  • Tabitha
    Tabitha almost 5 years
    @heymatthew the reason it is being downvoted is because it didn't answer the question asked. It answered a completely different unrelated question.
  • mtraceur
    mtraceur almost 5 years
    @iconoclast This is a meaning relativity problem: "login shell" also has a very specific technical meaning, which in the case of zsh it means "the shell sourced .zprofile and .zlogin, not only .zenv and .zshrc, as it is documented to do when started in login "mode", and it added l to the list of characters in $- to indicate this).
  • alper
    alper over 2 years
    chsh: /usr/local/bin/zsh is an invalid shell. I had to do: sudo sh -c "echo '/usr/bin/zsh' >> /etc/shells" && chsh -s /usr/bin/zsh
  • Andrew
    Andrew about 2 years
    Why do we pass the --login flag with the command option rather than selecting the Login shell option?