44

I was trying new dev environments including zsh and oh-my-zsh. Now that I have installed oh-my-zsh, it starts by default on my terminals (iTerm2 and terminal) always start with zsh and with the settings on from oh-my-zsh. I was wondering if it was possible to "disable" or stop using zsh and its setup with oh-my-zsh without having to uninstall oh-my-zsh? It would also be nice to know how to turn them back on too.

Currently, my terminals goes into zsh automatically (I think) and use the oh-my-zsh automatically. I want to have more control over that and me able to control both, when the zsh is being used and when the oh-my-zsh features are being used.

One thing I am also interested on knowing is, how do the terminal applications know which shell to start running on start up. That would be nice to be able to control too!

If you explain as much as you can of the "why" of every command you give me, that would useful! :)


I am on OS X. Not sure if that matters, but I tend to like answers more that are more applicable to more general Unix environments rather to my own.

2
  • you want to stop using zsh? or oh-my-zsh? which?
    – strugee
    Commented Jun 15, 2014 at 3:12
  • either and both. i.e. I want to be able to control both, when I am using zsh and oh-my-zsh Commented Jun 15, 2014 at 3:21

6 Answers 6

42

The wording of your question is ambiguous, so I can't tell if you mean you want to stop using zsh or you want to stop using oh-my-zsh. I will cover both.

Disabling zsh

Simply run chsh and select whatever shell you were using before. If you don't know what shell you were using before, it is almost certainly bash. This command changes the "login shell" that is associated with your user. Essentially, it changes your default shell.

You will need to open a new terminal window for changes to take effect. If this does not work, you will need to log out and log back in again to reinitialize your environment.

Disabling only oh-my-zsh

  1. Check if ~/.zshrc.pre-oh-my-zsh exists. It probably does. (This file will have been created when the oh-my-zsh installation script moved your previous .zshrc out of the way. .zshrc is a startup file of zsh, similar to .bashrc for bash.)
  2. If it does, do mv ~/.zshrc ~/.zshrc.oh-my-zsh. This will put the oh-my-zsh-created .zshrc out of the way, so we can restore the original, by doing mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc.
  3. If it does not exist, open ~/.zshrc in a text editor. Find the line that says source $ZSH/.oh-my-zsh and either comment it out or remove it. This will disable the initialization of oh-my-zsh.

You will need to restart your shell for changes to take effect.

3
  • I apologize about my wording. I believe I clarified it. Is it clear now? Thanks btw. Commented Jun 15, 2014 at 3:29
  • @CharlieParker yeah, I was being lazy. I'll expand the answer, maybe explain a bit of the "why".
    – strugee
    Commented Jun 15, 2014 at 3:31
  • 1
    @CharlieParker in case you didn't notice, I updated this answer. let me know if anything can be improved.
    – strugee
    Commented Jun 16, 2014 at 0:03
18

chsh -s /bin/bash

To manually set a new default shell, do chsh -s /my/ new/shell, eg chsh -s /bin/bash. Then simply reopen your shells.

3
  • 1
    Best answer, should be accepted !
    – code-8
    Commented Mar 24, 2020 at 21:11
  • How to change it back to use zsh?
    – Dracula
    Commented Aug 20, 2021 at 21:28
  • @ParthTamane chsh -s /bin/zsh Commented Feb 3, 2022 at 16:31
15

As it's a bit hidden in @Gilles answer the quick way to load zsh without any config e.g. .zshrc .zshenv etc

zsh -f

This is useful when you want to test if anything in your config is preventing some feature of zsh from working.

3

ZSH Config Switching

If you want to test different zsh configuration frameworks (oh-my-zsh, zprezto, etc) and switch between them, your best bet is using symbolic links for ~/.zsh, ~/.zshrc, ~/.zlogin, ~/.zlogout, ~/.zprofile, and ~/.zshenv. You may want to create a shell scripts for each framework to create those symlinks for faster switching.

Put your framework configurations in their own folders. For each framework.

  • Install the framework in its own folder if possible, otherwise
  • If the framework forces installation to ~/.zsh, then
    • Protect the current ~/.zsh first. Either
      • remove the ~/.zsh symlink; rm ~/.zsh, or
      • move the ~/.zsh folder; mv ~/.zsh ~/.zsh.backup
    • Run the framework installer.
    • Move the framework folder to its own directory. e.g. mv ~/.zsh ~/.oh-my-zsh.
  • Repeat for each framework.

Once done, create a shell script for each framework to create the necessary symlinks. Here's an example for zprezto, since I already use it.

$ mkdir ~/bin
$ cat <<EOF > ~/bin/use-zprezto
#!/bin/bash
SYMLINKS=".zsh .zshrc .zshlogin .zshlogout .zshprofile .zpreztorc .zshenv .zshrc"
CONFIG_HOME="$HOME/.zprezto"

# check for unexpected error conditions
for sym in $SYMLINKS; do
   # report an error and quit if $sym exists and is not a symlink
   [[ -e "$HOME/$sym" -a ! -h "$HOME/$sym" ]] && { echo "error:  '$HOME/$sym' is not a symlink!"; return 1; }
done

# now create the symlinks now that nothing should go wrong
for sym in $SYMLINKS; do
   # remove old symlink if it exists
   [[ -h "$HOME/$sym" ]] && rm -f "$HOME/$sym"
   # create new symlink
   ln -s "$CONFIG_HOME/$sym" "$HOME/$sym"
done

# uncomment next line to start a new zsh shell.  CAUTION: each call is a zsh shell inside a zsh shell.  Too many calls will put you in limbo :D
#/usr/bin/env zsh
EOF

$ chmod 700 ~/bin/use-zprezto

This script is fairly simple and relies on the fact that all my symlinks are organized with the same pattern. You can copy&paste the remove and create lines after the loop for symlinks you have that don't follow the pattern.

Once done, use ~/bin/use-zprezto--or ~/bin/use-whatever--to switch between zsh frameworks.

Note that changes only take effect in new zsh shells, not existing shells.

Shell Switching

It's a bit dangerous, but if you're so inclined, you can use a symlink for your shell command and set the symlink as your default shell. You can then follow the use-* script method above to change your default shell.

As an example with zsh...

$ mkdir ~/bin
$ cat <<EOF > ~/bin/use-zsh
#!/bin/bash
# check for valid shell symlink
if [[ ! -h "$HOME/.shell" ]]; then
  echo "error: $HOME/.shell is not a symlink!"
  return 1
fi

# remove existing shell symlink if it exists
[[ -h "$HOME/.shell" ]] && rm -f "$HOME/.shell"

# create new shell symlink, but warn user if this fails!
if ! ln -s /usr/bin/zsh "$HOME/.shell"; then
  echo "ERROR: failed to create $HOME/.shell symlink.  Manually create the symlink or future logins will fail!."
  return 2
fi
EOF

$ chmod 700 ~/bin/use-zsh

The reason this is dangerous is that you cannot login under a user if the shell stored in /etc/passwd is not a valid program. So you can lock yourself out of your account if you're not careful; i.e. your ~/.shell symlink is broke or doesn't point to an interactive program. You're welcome to try this with a user account, but this is NOT RECOMMENDED for your root account.

If you still want to continue, then

$ ~/bin/use-zsh         # ensures ~/.shell exists for chsh
$ echo "$HOME/.shell | sudo tee -a /etc/shells    # add symlink to system's list of valid shells
$ chsh -s ~/.shell      # changes default shell in /etc/passwd for $USER
3

You can tell zsh to load its per-user configuration files from a different directory by setting the environment variable ZDOTDIR before starting zsh.

If you want to start zsh without loading your configuration files, set ZDOTDIR to a non-existent directory. If you want to skip system configuration files (apart from /etc/zshenv), you can run zsh -f. If you want to skip system configuration files but run the per-user files, run zsh -d.

For example, if you want to test-drive oh-my-zsh without making it the default, don't put the .zshrc from oh-my-zsh in your home directory. Instead, put it somewhere else, eg. in ~/.oh-my-zsh, and then run ZDOTDIR=~/.oh-my-zsh zsh when you want to use oh-my-zsh.


Terminal applications run the shell indicated by the SHELL environment variable. If this variable is unset, they run the login shell indicated in the user database (/etc/passwd). You can request a different application when you start a terminal emulator, e.g. xterm -e fish.

0

in my case I only wanted to disable the ohmyzsh-behavior when on a nfs mount. The ohmyzsh prompt (with git status) caused terrible delays. But I did want not disable all of the zsh settings because of starting up with -f

With help of Gilles answer I did the following:

  • create directory zsh
  • copied ~/.zprofile to zsh/.zshrc
  • edited out the sourcing of the ohmyzsh-profile in zsh/.zshrc
  • start a new shell with ZDOTDIR=$HOME/zsh zsh

Now a zsh is loaded with all the settings and aliases of the normal .zprofile. Keep in mind that changes in .zprofile are not reflected in zsh/.zshrc. When needed, this has to be solved with includes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .