Linux – Switching to zsh

zsh (“zee shell”) is awesome.  Alas, its still not installed by default in most Linux distributions.  Here’s how to install & configure zsh on Debian 9:

grokman@li598-26:~$ sudo apt-get update
[sudo] password for grokman:
Ign:1 stretch InRelease
Get:2 stretch/updates InRelease [94.3 kB]
Get:3 stretch-updates InRelease [91.0 kB]
Hit:4 stretch Release
Fetched 185 kB in 0s (434 kB/s)
Reading package lists... Done
grokman@li598-26:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
grokman@li598-26:~$ sudo apt-get install zsh
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
Suggested packages:
The following NEW packages will be installed:
  zsh zsh-common
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,270 kB of archives.
After this operation, 15.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 stretch/main amd64 zsh-common all 5.3.1-4 [3,454 kB]
Get:2 stretch/main amd64 zsh amd64 5.3.1-4+b2 [816 kB]
Fetched 4,270 kB in 0s (48.7 MB/s)
Selecting previously unselected package zsh-common.
(Reading database ... 34252 files and directories currently installed.)
Preparing to unpack .../zsh-common_5.3.1-4_all.deb ...
Unpacking zsh-common (5.3.1-4) ...
Selecting previously unselected package zsh.
Preparing to unpack .../zsh_5.3.1-4+b2_amd64.deb ...
Unpacking zsh (5.3.1-4+b2) ...
Setting up zsh-common (5.3.1-4) ...
Processing triggers for man-db ( ...
Setting up zsh (5.3.1-4+b2) ...

We can see the zsh version that was installed in the install output, but we can confirm that version is actually running with:

grokman@li598-26:~$ zsh --version
zsh 5.3.1 (x86_64-debian-linux-gnu)

Now, we can set our login shell to be zsh with the chsh command.  Note that we have to log out and back in to see the change.  When we log back in we get prompted for how we want to configure our zsh.  If you have  custom config already in mind, press 0.  If not you can start with the default option 2:

grokman@li598-26:~$ chsh -s $(which zsh)
grokman@li598-26:~$ exit
root@li598-26:~# su - grokman
This is the Z Shell configuration function for new users,
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses --- 2
/home/grokman/.zshrc:15: scalar parameter HISTFILE created globally in function zsh-newuser-install
(eval):1: scalar parameter LS_COLORS created globally in function zsh-newuser-install
grokman@li598-26 ~ %

You will probably notice your prompt change a bit:


To set it up like so: 

We can edit our ~.zshrc file:

grokman@li598-26 ~ % vim .zshrc

Change the contents of the .zshrc to be:

# grokman's basic .zshrc
# The following lines were added by compinstall
zstyle :compinstall filename '/home/grokman/.zshrc'
autoload -Uz compinit
# End of lines added by compinstall
PROMPT='%{$(pwd|grep --color=always /)%${#PWD}G%} %(!.%F{red}.%F{cyan})%n%f@%F{yellow}%m%f%(!.%F{red}.)%#%f '

alias ll='ls -lia'
alias sd='sudo shutdown -r 0'

Save the file & then we can just “source” the .zshrc like so:

grokman@li598-26 ~ % . ~/.zshrc

Now your prompt should look like so: 

zsh kind of has a bit of a cult following (basically, people who get a bit overly- caught up in the way their prompt looks, haha!).  In recent times, a nice little zsh project has cropped up which allows you to kind of go nuts with zsh, giving you the ability to integrate your zsh more tightly with apps like Git, PostgreSQL, Python & many more.  Depending on what you’re doing, it may be worthwhile to check it out:  Oh My zsh!

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

Notice: Undefined index: total_count_position in /var/www/wordpress/wp-content/plugins/social-pug/inc/functions-frontend.php on line 46