Linux change bash to zsh

How to Make ZSH the Default Shell in Ubuntu?

Zsh (Z shell) is an alternative shell to the more commonly used Bash shell in Linux-based operating systems like Ubuntu. It is designed to be more user-friendly and customizable than Bash. It offers many features that make working in the command-line interface easier and more efficient, such as plugins and themes, a customizable prompt, command history, improved scripting capabilities, better interactive features, tab completion, etc.

This article will illustrate various methods to make the Zsh the default shell in Ubuntu.

Prerequisites: Install ZSH on Ubuntu

To make the Zsh the default shell, make sure that it is installed on the system. To install the ZSH shell in Ubuntu, follow the step-by-step instructions in our guide, i.e., “Install Zsh on Ubuntu”.

Method 1: Using the “chsh” Command

The easiest way to change the default shell to Zsh is possible via the “chsh” command. The “chsh” command changes the default login shell for a user. The “s” option specifies the new shell that should be used as the default login shell:

With the “chsh -s” command, provide the path of the shell which is possible through the “$(which zsh)” or “/usr/bin/zsh”:

After entering the password, close the terminal window and reopen it.

Verify: Zsh Default Shell

The output shows the Z shell has been set as the default shell.

Method 2: Editing the /etc/passwd File

The “/etc/passwd” file contains the user’s related information, and it can be edited to change the default shell of the specific user. Let’s see how it works:

Open the file via any text editor, i.e., nano:

It navigates to the specified mentioned file. In this file, find the line that starts with the user name.

In our case, the username is “itslinuxfoss”, Navigate to the particular line and change “/bin/bash” to “/usr/bin/zsh”:

Press “Ctrl + X”, then press Y to save the changes, and then press “Enter” to exit the editor.

Now, every time when the user opens a terminal window, Zsh will be the default shell. To perform any configuration, press “2” as seen in the below figure:

The output shows the Z shell has been set as the default shell.

Method 3: Using the usermod Command

Users can also change the default shell using the “usermod” command. For this, use the “usermod” command by specifying the current username. For instance, the current username is “itslinuxfoss”:

$ sudo usermod -s /usr/bin/zsh itslinuxfoss

After executing the above command, close the terminal window and reopen it.

Verify: Zsh Default Shell

Close the terminal and reopen it. Users can observe that the Zsh is set as the default shell. Now, execute any command such as echo “Hello World”:

Читайте также:  Linux find files not named

The output shows the Z shell has been set as the default shell and execute the input command like Bash.

Conclusion

To make Zsh the default shell in Ubuntu, execute the “chsh -s $(which zsh)” or “sudo usermod -s /usr/bin/zsh ” commands. Additionally, users can edit the “/etc/passwd” file by changing the phrase “/bin/bash” to “/usr/bin/zsh” in the text editor. This guide has illustrated different methods to make the ZSH the default shell in Ubuntu.

Источник

How To Change The Default Shell In Linux (Bash, Zsh, Fish, Etc.)

change default shell linux

This article explains how to change the default shell in Linux. Using this you can set Bash, sh, Zsh, Csh, Fish, etc. as your shell.

The article includes instructions for changing the login shell from the command line using chsh, or changing the shell only for a particular terminal application. While the article is targeted at Linux users, this should also work on other Unix-like systems.

How to change the default login shell using chsh (from the command line)

To change the default login shell we’ll use chsh , a command line tool to change the login shell.

This program changes the login shell by modifying the /etc/passwd file and setting the $SHELL environment variable. You can override the default shell in a terminal application, by setting the shell from the terminal settings — see the second part of this article for details.

A note for Fedora users. Fedora doesn’t have chsh installed by default and to use it, you must install a package called util-linux-user . If you want to skip installing this package, you can use lchsh instead to change the login shell, which is available by default:

It’s important to note that using chsh, a normal user may only change the login shell for the current account, while the superuser may change the login shell for any account, including the root account. Also, the default behavior for non-root users is to accept only shells listed in the /etc/shells file, and issue a warning for root user.

So before changing your shell, list all the shells listed in the /etc/shells file from your Linux system by using the following command:

$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/bin/rbash
/bin/dash
/usr/bin/tmux
/bin/zsh

If the shell you want to use is not listed here, it may not be installed on your system. So install it (for example, install Zsh on Debian / Ubuntu / Linux Mint / Pop!_OS using: sudo apt install zsh ) and check again.

To change the shell for your user, run:

This runs chsh in an interactive mode, asking you for the password, then listing your current shell (most Linux distributions use Bash as the default shell) and asking you to enter a value for your new shell. Here’s the command with its output:

$ chsh
Password:
Changing the login shell for logix
Enter the new value, or press ENTER for the default
Login Shell [/bin/bash]:

To change your shell, type the path to the new shell (which exists in /etc/shells ) and press the Enter key.

For example, to change the shell for the current user from Bash to Zsh:

$ chsh
Password:
Changing the login shell for logix
Enter the new value, or press ENTER for the default
Login Shell [/bin/bash]: /bin/zsh

In case you’re using a chsh version that doesn’t launch with an interactive prompt after executing chsh , change the login shell for your user directly:

Читайте также:  Linux building custom kernel

E.g. to change the shell to Zsh:

After changing your account’s shell, logout and re-login to use the new shell.

To change the login shell for another user or for the root user, login to the shell prompt as root using su — , sudo -i , sudo su , etc., and run:

  • To change the shell for the root account (and when prompted, enter the login shell you want to use, with its full path):
  • To change the shell of another user (this also works for the root user, using root as the username):

This time we’ve used chsh with the -s option, which changes the login shell directly (doesn’t run in an interactive mode). Here, SHELL is the new shell (e.g. /bin/zsh ) and USERNAME is the user for which you’re changing the shell; for example, to change the shell to /bin/zsh for the user Logix , you’d use: chsh -s /bin/zsh Logix ).

Change the shell for your user in a terminal application

You can use a shell that’s different from the login shell ( $SHELL ) for a particular terminal application, if that application allows setting a custom shell or running a custom command instead of the default shell.

As a side note, you may also change the current shell (non-permanent change) by typing the shell command you want to use in a terminal (e.g. if you type «zsh», you’ll switch to using Zsh for that session; exit by typing «exit».).

Take GNOME Terminal for example (used in GNOME and Cinnamon desktops as the default terminal). Open its Preferences , click on the current active profile (usually called Default or Unnamed if you haven’t changed it or added new profiles) in the left-hand sidebar, then click on the Command tab:

This is where you can set a custom shell to be used with this application only. Enable the Run a custom command instead of my shell option, then in the Custom command field enter the full path to the shell you want to use, e.g. /bin/zsh , /bin/bash , etc.

In Xfce4 Terminal, open the Preferences and on the General tab you’ll need to enable an option called Run a custom command instead of my shell , then enter the custom command below that (this being the shell you want to use with this terminal, e.g. /bin/zsh , /usr/bin/fish , etc.).

Using KDE Plasma’s Konsole, go to Settings -> Edit Current Profile , and on the General tab, change the Command field to the full path of the shell you want to use (once again, something like: /bin/zsh , /bin/bash , /usr/bin/fish , etc.).

Using Guake, you can change the user shell from its Preferences , on the Shell tab, where you’ll find an option called Default interpreter that allows choosing any shell listed in /etc/shells .

For terminals that allow running a custom shell you should also find an option that allows running the command as a login shell (usually called just that: «Run command as a login shell»). To read on the differences between a login shell and an interactive shell, see this page.

Setting this is the same in most cases, so I won’t give any more examples. However, it’s worth noting that not all terminal applications have options to allow using a custom shell — in such cases, use the chsh command to change the login shell, as explained above.

Источник

How to make ZSH the default shell?

I am trying to set ZSH as my default shell, however it keeps reverting back to bash. I have tried this code:

Читайте также:  Mac адрес роутера linux

Also tried these commands without sudo. Any ideas on what else I need to do. When running ZSH from within bash it loads up and works fine but I’d like to set it as the default shell.

quick answer that worked for me: logging out and then logging back in to the desktop session fixed it for me.

7 Answers 7

without sudo should work. If you use sudo it will change the shell not for your working user but for root

Finally, log out of your computer and log back in.

  • Do you have zsh installed (ii)? dpkg -l zsh
  • Is your shell set to zsh? Last field of grep $USER /etc/passwd
  • Is Zsh a valid login shell? grep zsh /etc/shells

Find the line with your username:

username:x:1634231:100:Your Name:/home/username:/bin/bash 

and replace bash with zsh:

username:x:1634231:100:Your Name:/home/username:/bin/zsh 

Log out and log in back for the changes to take effect.

You should be very careful with this approach — it’s not usually the best idea to go mucking around with /etc/passwd

To Log out and log in back is very important step. Maybe it is should even be somehow emphasized.

open your bashrc file in your favourite editor

then add the line below top of the file

It will execute the command every time you load the terminal and run your zsh shell.

Thanks that did it. @Timo I did the change on /etc/passwd and or chsh but my default kept going back to bash. I added exec zsh as per posted response and it worked.

This was the only one that worked for me on the work machine with active directory, my username is always not found, whoami works fine, but certain commands such as chsh always cannot locate my username

I had an issue with permissions to change shell under the current user but next helps me (you should set correct ‘zsh’ folder for your computer):

If zsh is not /bin/zsh then chsh won’t work. On Ubuntu it is /usr/bin/zsh. so doing chsh -s /usr/bin/zsh or chsh -s `which zsh` should work. Also need to re-login to desktop session.

On mine (14.04, with zsh from main repo), there are two zsh’s, and they are both two-layer symlinks: /usr/bin/zsh -> /etc/alternatives/zsh-usrbin -> /bin/zsh5 and /bin/zsh -> /etc/alternatives/zsh -> /bin/zsh5

Strange, the «accepted» answer didn’t work for me as I got

chsh: PAM: Authentication failure 

To solve this issue edit your /etc/passwd and make sure it points to the zsh location. (You can find this by running «which zsh») In my case my user called «webmaster» looked like this:

webmaster:x:1001:1001:webmaster. /var/www/webmaster:/usr/bin/zsh 

I believe it’s supposed to ask for a password. I got the same error on my previous mint install. Current one worked fine though

Someone else had the same problem, and it turned out they had ran chsh -s zsh , which made their passwd entry incorrect.

As well as chsh (or editing /etc/passwd, which does the same thing), you might need to edit the settings in your terminal emulator (Gnome terminal, Konsole, xfce4-terminal, etc). Your profile will probably have a login shell, which will be run when you open a new tab instead of the shell in /etc/passwd.
In Konqueror it’s Settings | Edit Current Profile | Command .

You must log in to answer this question.

Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Источник

Оцените статью
Adblock
detector