Set up zsh on your Fedora system

For some people, the terminal can be scary. But a terminal is more than just a black screen to type in. It usually runs a shell, so called because it wraps around the kernel. The shell is a text-based interface that lets you run commands on the system. It’s also sometimes called a command line interpreter or CLI. Fedora, like most Linux distributions, comes with bash as the default shell.  However, it isn’t the only shell available; several other shells can be installed. This article focuses on the Z Shell, or zsh.

Bash is a rewrite of the old Bourne shell (sh) that shipped in UNIX. Zsh is intended to be friendlier than bash, through better interaction. Some of its useful features are:

  • Programmable command line completion
  • Shared command history between running shell sessions
  • Spelling correction
  • Loadable modules
  • Interactive selection of files and folders

Zsh is available in the Fedora repositories. To install, run this command:

$ sudo dnf install zsh

Using zsh

To start using it, just type zsh and the new shell prompts you with a first run wizard. This wizard helps you configure initial features, like history behavior and auto-completion. Or you can opt to keep the rc file empty:

zsh First Run Wizzard

First-run wizard

If you type 1 the configuration wizard starts. The other options launch the shell immediately.

Note that the user prompt is % and not $ as with bash. A significant feature here is the auto-completion that allows you to move among files and directories with the Tab key, much like a menu:

zsh cd Feature

Using the auto-completion feature with the cd command

Another interesting feature is spelling correction, which helps when writing filenames with mixed cases:

zsh Auto Completion

Auto completion performing spelling correction

Making zsh your default shell

Zsh offers a lot of plugins, like zsh-syntax-highlighting, and the famous “Oh my zsh” (check out its page here). You might want to make it the default, so it runs whenever you start a session or open a terminal. To do this, use the chsh (“change shell”) command:

$ chsh -s $(which zsh)

This command tells your system that you want to set (-s) your default shell to the correct location of the shell (which zsh).


Photo by Kate Ter Haar from Flickr (CC BY-SA).

For System Administrators Using Software

12 Comments

  1. It’s when I discovered Oh-My-Zsh that I definitely changed from bash to zsh, and never looked back 😉

  2. Using with “antigen” is very useful!

  3. Really good tip, ZSH is much powerful! 😀
    A full guide to have a really, really powerful terminal using it: https://medium.com/@ivanaugustobd/seu-terminal-pode-ser-muito-muito-mais-produtivo-3159c8ef77b2 (it’s in Brazilian Portuguese, but can be easily translated using your favorite tool)

  4. Dirk

    I use ZHS with antigen and various activated plug-ins on Fedora for years now. And I don’t want to miss it.

  5. Leslie Satenstein

    Whats wrong with bash?

    • Creak

      Bash is very good, but quite limited in its features. I thought bash was largely enough for me (I’m not a hardcore shell user), but I tried zsh, just to see what it is.

      What really changed my mind about zsh is when I configured it with Oh-My-Zsh (or Antigen, which is an attempt to make Oh-My-Zsh modular). Some day-to-day features are so useful, I just get frustrated when I go back to bash 😀

    • Brian Vaughan

      Nothing. ZSH just has some syntactic sugar some may like. I played with it for a while, and used Oh-My-Zsh, which has some cute tricks for the command line.

      But, I’d never consider installing Oh-My-Zsh on a production system. And, I never got around to learning how to use ZSH’s unique features for scripting; it occurred to me that it didn’t make a lot of sense to do so. BASH is ubiquitous, and if BASH isn’t adequate to a task, I’d rather use Perl or Python, which are nearly as ubiquitous.

  6. What happens when you run bash or the usual commands on Zsh? I suppose ~/.bashrc, scripts, etc. continues to work as usual.

    • If you run bash, you just goes to bash through the normal process that include reading .bashrc .bash_profile and all other files needed to run bash. The commands just call programs, so yes, they work as usual: ls, cd, mv, cp, ln and everything works as usual, regular expression matching is a little different, the work with wildcards is also a little different, and the scripting is totally different. The scripts made for bash including th shabang works as usual.

    • Brian Vaughan

      Zsh, like Bash, is POSIX-compliant; the command line functions basically the same way, scripts that stick to POSIX features only should work with either shell, and a lot of Bash’s special features are also present in Zsh.

      Normally, a shell script starts with a shebang, as in “#!/bin/bash” or “#!/bin/zsh”, which specifies the script interpreter. So a properly written script would run correctly, regardless of which shell the user is using at the command line.

      You can launch an instance of Bash from within an instance of Zsh, or vice versa, just as you can launch a new instance of Bash from within an instance of Bash.

      ~/.bashrc, and the other related dotfiles that begin with “.bash”, are specific to Bash. Zsh uses ~/.zshrc . There are other dotfiles that are independent of a particular shell, e.g., .profile.

    • Creak

      Zsh is more for your day-to-day use of the command line. It brings useful features that bash simply doesn’t have (e.g. the exceptional completion system).

      But if you’re writing a script for general purpose, always use a shebang to sh (i.e. #!/bin/sh) at the top of your script. Doing so, you’re scripts will run in a strong, cross-compatible shell environment.

  7. bladekp

    Here you can find some nice startup confings for your ZSH: https://bitbucket.org/Vifon/zsh-config

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions