Skip to Content

Ubuntu 14.04 Z Shell (zsh) Installation and Basic Configuration

Ubuntu 14.04 Z Shell (zsh) Installation and Basic Configuration

Initial notes on installing plus base setup of Z Shell.

Listed here are some of its often touted features.

  • Auto-completion
  • Auto-correction
  • Scripting capabilities
  • Extensibility with modules
  • Improved globbing
  • Improved array handling

1 – Installation

Update the apt-get package manager’s database.

[alert-announce]

  1. $ sudo apt-get update

[/alert-announce]

Install zsh through the apt-get package manager.

[alert-announce]

  1. $ sudo apt-get install zsh

[/alert-announce]

2 – zsh-newuser-install

Run Z Shell for the first time to begin the new user config.

[alert-announce]

  1. $ zsh

[/alert-announce]

If it doesn’t run or drop into the config then you can use:

[alert-announce]

  1. $ zsh /usr/share/zsh/functions/Newuser/zsh-newuser-install -f

[/alert-announce]

Which will invoke the new user config manually.

Work through the new prompt screen as directed, typing 0 remembers an edit but does not save it until it is entered again on the root prompt screen.

[alert-announce]

  1. (1) Configure settings for history, i.e. command lines remembered
  2. and saved by the shell. (Recommended)

[/alert-announce]

On the first option 0 will suffice and keeps the default settings.

[alert-announce]

  1. (2) Configure the new completion system. (Recommended.)

[/alert-announce]

On the second option pressing 1 and turning on completion with default options is enough.

[alert-announce]

  1. (3) Configure how keys behave when editing command lines. (Recommended.)

[/alert-announce]

With the third option you can set the key’s shell line editor to behave like Emacs or Vi. Set it with 1 and press e for emacs and v for vi.

[alert-announce]

  1. (4) Pick some of the more common shell options. These are simple “on”
  2. or “off” switches controlling the shell’s features.

[/alert-announce]

In the fourth option I set 1, 2, and 3 to on, enabling them.

Finally entering 0 at the root menu exits and saves these new settings.


3 – Configuration Files Layout

When Z Shell starts, it sources the following files in this order:

/etc/zsh/zshenv
Commands to set the global command search path and other system-wide environment variables; it should not contain commands that produce output.

~/.zshenv
For per-user configuration. Generally used for setting some useful environment variables.

/etc/zsh/zprofile
This is a global configuration file, usually used for executing some general commands at login. On Arch Linux, by default it contains one line which sources the /etc/profile.

/etc/profile
This file should be sourced by all Bourne-compatible shells upon login: it sets up an environment upon login and application-specific settings. Again on Arch Linux, Z Shell will also source this by default.

~/.zprofile
This file is generally used for automatic execution of user scripts upon login.

/etc/zsh/zshrc
Another global configuration file.

~/.zshrc
The main user configuration file, and the one most often customised by users. This file is the one that will be used and changed in the next section.

/etc/zsh/zlogin
Another global configuration file.

~/.zlogin
Same as the previous file before it, except for individual-user configuration.

/etc/zsh/zlogout
A global configuration file, will be sourced when a login shell exits.

~/.zlogout
Same as the previous file before it, except for individual-user configuration.

4 – .zshrc Configuration File

The newly created zsh config file contents we just defined can be seen by opening it with a text editor. I’m using vim in this example.

[alert-announce]

  1. $ vim ~/.zshrc

[/alert-announce]

At the end of the config file append the following:

[alert-announce]

  1. autoload -U promptinit compinit
  2. promptinit
  3. compinit
  4. prompt bart

[/alert-announce]

Where bart is the name of the prompt you wish to use in your Z shell. For my example here I chose the bart theme.

To see possible prompts available and installed follow these commands from a Z shell terminal prompt.

[alert-announce]

  1. $ autoload -U promptinit
  2. $ promptinit
  3. $ prompt p

[/alert-announce]

To apply any changes immediately in the config file you can use:

[alert-announce]

  1. $ source ~/.zshrc

[/alert-announce]

Or exit and invoke a new Z Shell session.

[alert-announce]

  1. $ exit
  2. $ zsh

[/alert-announce]

Finally to make Z Shell your Linux user’s default shell on this account enter:

[alert-announce]

  1. $ chsh -s $(which zsh)

[/alert-announce]

Note: Do not include sudo with this previous command as it will alter the root user’s default shell instead.

The $SHELL variable stores your user’s current default shell path. It can be used to confirm the set default shell.

[alert-announce]

  1. $ echo $SHELL

[/alert-announce]

Alternative Method via oh-my-zsh

Oh-My-Zsh is an open source, community-driven framework for managing your ZSH configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes, and a few things that make you shout…

Instead of a manual setup many people choose to use oh-my-zsh to manage their zsh installations.

It can be acquired most easily by using either curl or wget

[alert-announce]

  1. $ curl -L http://install.ohmyz.sh | sh

[/alert-announce]

Or:

[alert-announce]

  1. $ wget –no-check-certificate http://install.ohmyz.sh -O – | sh

[/alert-announce]

Enable any of the plugins you want in your ~/.zshrc config file by setting them active:

[alert-announce]

~/.zshrc

  1. plugins=(git ruby)

[/alert-announce]

Change the ZSH_THEME environment variable in your ~/.zshrc to enable any of themes included in the package.

[alert-announce]

~/.zshrc

  1. ZSH_THEME=”af-magic”

[/alert-announce]