If you’ve been using Linux for a while, you’re probably familiar with Bash, the default shell that comes with most Linux distributions. But have you thought of switching to Zsh? Zsh is a robust shell that provides many things that Bash does not. In this post, we’ll look at the advantages of using Zsh as well as how to migrate from Bash to Zsh on Linux.
Table of Contents
Why Use Zsh?
Auto-completion
Zsh has a powerful auto-completion feature that can save you a lot of time when typing commands. It can complete not only command names but also file names, options, and arguments.
Better command-line editing
Zsh has more advanced command-line editing features than Bash. For example, you can edit a command in the middle of a line without having to move the cursor to the beginning of the line.
Better prompts
Zsh allows you to customize your prompt in many ways, including adding colors and displaying information about your system or current directory.
Plugins
Zsh has a vast collection of plugins that can extend its functionality. For example, the zsh-syntax-highlighting plugin highlights syntax errors in your commands.
Compatibility with Bash
Zsh is largely compatible with Bash, so you can use most of your Bash commands in Zsh.
How to Install Zsh
On Linux, you must first install Zsh before switching from Bash to Zsh. Zsh is available in most Linux distributions’ package repositories, so you can install it using your distribution’s package manager.
Ubuntu and Debian
sudo apt-get install zsh
Fedora
sudo dnf install zsh
CentOS and Red Hat
sudo yum install zsh
Arch Linux
sudo pacman -S zsh
Gentoo
sudo emerge -av zsh
openSUSE
sudo zypper install zsh
Set ZSH as your default shell
Once you’ve installed Zsh, you can switch to Zsh:
To set Zsh as your default shell, you can use the chsh
(change shell) command. Here’s how you can do it:
Open a terminal window and type the following command:
sudo chsh -s $(which zsh)
This command changes the default shell for your user account to Zsh.
If the command prompts you to enter your password, enter your user account password.
Log out and log back in again to make the change take effect.
Now, every time you open a terminal window or log into your Linux system, Zsh will be the default shell.
Set ZSH as your default shell for all users
To change the default shell for all users on a Linux system, you can use the usermod
command with the -s
option. Here’s how you can do it:
Open a terminal window and type the following command:
sudo usermod -s $(which zsh) USERNAME
Replace USERNAME
with the username of the user whose shell you want to change. If you want to change the shell for all users, you will need to run this command for each user.
If the command prompts you to enter your password, enter the password for the sudo
user.
Log out and log back in again for the change to take effect.
Now, every time a user logs into the Linux system, Zsh will be the default shell.
Set zsh as the shell for a new user
To set Zsh as the default shell for newly created users on a Linux system, you can modify the system default shell setting. Here’s how you can do it:
Open a terminal window and type the following command to edit the /etc/default/useradd
file:
sudo nano /etc/default/useradd
Find the line that starts with SHELL=
and change it to the following:
SHELL=/bin/zsh
This sets the default shell for new users to Zsh.
Save the changes to the file and exit the text editor.
Now, every time a new user is created on the system, Zsh will be the default shell.
Note that this setting only affects newly created users. For existing users, you will need to use the chsh or usermod command to change their default shell.
Conclusion
Zsh is a powerful shell that offers many features that are not available in Bash. By switching to Zsh and customizing it to your needs, you can improve your productivity and efficiency when working in the command line. Try it out and see for yourself!
Got any queries or feedback? Feel free to drop a comment below!