Set zsh as default linux

Making zsh default shell without root access

I am using my school’s computers and would like to use zsh instead of bash . I’d like to make it the default shell, but I cannot run a command such as $ chsh -s $(which zsh) because I don’t have admin privileges. Is there a way I can put something in my .bashrc or something that automatically calls zsh when it opens as a workaround? To clarify, zsh is already installed.

Placing zsh in .bashrc would make it always execute even when bash is called explicitly. Better place it in .bash_profile instead.

8 Answers 8

Create .bash_profile in your home directory and add these lines:

export SHELL=/bin/zsh exec /bin/zsh -l 

Update: .profile may work as a general solution when default shell is not bash. I’m not sure if .profile may be called by Zsh as well that it could go redundant but we can do it safely with a simple check:

export SHELL=/bin/zsh [ -z "$ZSH_VERSION" ] && exec /bin/zsh -l 

We can also use which to get the dynamic path of zsh which relies on the value of $PATH :

export SHELL=`which zsh` [ -z "$ZSH_VERSION" ] && exec "$SHELL" -l 

What if a Linux admin (root) changes your default shell to something other than bash (but not zsh), for example ksh? Then .bash_profile won’t get referenced. How about put this in .profile instead?

@JoshuaHuber Last test I made, .profile didn’t work. Also wouldn’t .profile be called by Zsh ? It could go redundant. Haven’t checked that yet though. (Update: It did work now, not sure what mistake I made before.) Any thoughts about possible drawbacks with using .profile ?

@konsolebox Bash only sources .profile if .bash_profile doesn’t exist (unless you manually source it from .bash_profile , of course). Specifically, bash sources the first one of the files [ .bash_profile > .bash_login > .profile ] it finds. It only looks for .profile as a POSIX (Bourne shell) compatibility feature.

@pyrocrasty Indeed. Just as said in the manual: «After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.»

It worked for to set up a new terminal profile with Run custom command instead of my shell changed to zsh . .bash_profile and .profile didn’t work (the files were not even executed, Fedora 26 on a university computer).

Normally you can use chsh as a non-root user. But it’s occasionally disabled, usually in sites that use some form of networked user database like NIS and LDAP. There might be a ypchsh (NIS) or chsh.ldap (LDAP) instead.

Читайте также:  Create user and groups in linux

chsh will also usually allow only some approved shells, typically the ones listed in /etc/shells .

If you can’t use chsh or its variants at your site, then arrange for your login shell to exec your favorite shell, and set the SHELL variable to point to your favourite shell.

    If your login shell is sh , dash or ksh : the file you need to edit is ~/.profile . Beware that this file is read at the beginning of an interactive session as well as by some non-interactive session startup scripts (e.g. for X11 sessions), so you need to take care: only call exec (which replaces the current process) when the current shell is interactive. Except for the Bourne shell (the /bin/sh of Solaris 10 and before), you can tell that a shell is interactive by the presence of i in the option list ( $- ).

preferred_shell= if [ -x /bin/zsh ]; then preferred_shell=/bin/zsh fi … if [ -n "$preferred_shell" ]; then case $- in *i*) SHELL=$preferred_shell; export SHELL; exec "$preferred_shell";; esac fi 

chsh will also usually allow only some approved shells, typically the ones listed in /etc/shells This was the key. I have added zsh with full path here and it worked.

If you can’t run chsh because you don’t have admin privileges, talk to someone who does.

Most likely you can’t use chsh as non-root because the system you’re using is configured so that chsh wouldn’t work, for example because the system uses NIS or LDAP rather than just the /etc/passwd file. Or perhaps your system’s administrator just wants to maintain some control.

The procedure for changing your shell depends on your organization’s policies. There may be a local command that does what chsh normally does. Or you may need to submit a support ticket requesting a shell change.

Most of the other answers are good, but if your administrators are reasonably responsive you might not want to bother hacking your startup scripts. I’d probably just invoke zsh -l manually after logging in until the administrator gets around to updating my account.

Another thing to keep in mind: Sometimes different shells can use the same startup files. For example, sh and bash can both execute $HOME/.profile , and csh and tcsh can both execute $HOME/.login and $HOME/.cshrc (though shell-specific startup files like .bashrc , .bash_profile , and .tcshrc can override those). If your default shell is /bin/csh and you want to use /bin/tcsh , updating your .login to invoke /bin/tcsh -l could create an infinite loop. zsh doesn’t happen to execute bash -specific startup files, so that’s not an issue for you.

Most shells set variables that identify which shell you’re running ( $BASH_VERSION , $tcsh , $ZSH_VERSION ). If you’re going to write startup code to invoke your preferred shell, it’s not a bad idea to enclose it in an if so it’s executed only if you’re not already running that shell. Using the code from konsolebox’s answer:

if [ "$" = "unset" ] ; then export SHELL=/bin/zsh exec /bin/zsh -l fi 

(The added complication of checking «$» rather than just «$ZSH_VERSION» allows for the possibility that you’ve done set -o unset , an option that causes a reference to an undefined variable to be an error.)

Читайте также:  64 битные версии linux

Источник

Install the Awesome Zsh and Make it the Default Shell

This tutorial will give you a short introduction to Zsh, steps to install Zsh and make it a default shell whenever you login to terminal.

What is Zsh (Z Shell)?

Z Shell (zsh in short), is a shell just like bash. It is used as a login shell (where you get a greeting and you will type in username and password) and as a command line interpreter (where you type Linux commands such as ls, cd).

You might wonder why someone needs to switch if every shell does these two functions. One of the main reasons is that his/her’s relative experience with different shells. And another reason is that each shell has unique features such as auto-completion, frequently used commands listing, etc. Feel free to share your reason in the comments.

How to install Zsh

This tutorial is tested on Ubuntu 18.04 LTS. It should work with other versions of Ubuntu as well. If not, tell us in the comments.

You can install zsh with following commands in Debian/Ubuntu based distributions:

sudo apt-get update sudo apt-get install zsh

You need sudoer rights to run above commands. If you don’t have such rights, contact your system admin. If you are the administrator, then refer to this article to learn about creating a sudoer.

In Fedora, Red Hat and CentOS, you can use the DNF package manager to install Zsh:

To check whether you have installed zsh correctly or not, run zsh by zsh —version.

Once done with the installation, you need to do a little configuration setup (if you haven’t done it already). First, change the shell by typing zsh in the terminal to get a prompt like this.

zsh shell in Linux

If you want to explore the options choose 1 and set it up. But I would recommend choosing 2 for now and then change the configuration whenever you need it.

Note that when you are running zsh for the first time and you accidentally happened to have one of these files (.zshenv .zshrc, .zlogin), the above prompt will not appear at that situation. Delete the files if you want to avoid using older configurations and run zsh again.

Make zsh the default shell

You can make any shell as your default shell if you know the location(or symbolic link) of the shell. In our case, zsh has a symbolic link /bin/zsh.

Above command will set zsh as the default shell for seeni. after a getting a password to check whether user running this command is “seeni,”. If you are the doing for it another user and you are the root or you have sudoer permissions, prepend sudo to the above command as follows.

Читайте также:  Pg dump postgresql linux

When you login the next time, check which shell you are using. If it’s zsh, this means that zsh is now the default shell on your system.

Congratulations! You manage to install zsh and make it the default shell. I hope you found this article useful. If you have suggestions or questions about this article, please let us know in the comments.

Источник

Set zsh as the default shell in your terminal.

How to set ZSH as the default shell in your terminal.

ZSH also called the Z shell, is an extended version of the Bourne Shell (sh), with plenty of new features, and support for plugins and themes. Since it’s based on the same shell as Bash that makes it easy for use and switching over is a breeze. Open vim or your favorite code editor

Now we need to edit the file and add the following line to the end of the file remember to add a comment just to remember, what is that line of code task.

It will execute the command every time you load the terminal and run your zsh shell. This is not the only way that you can get to the goal of setting zsh as the default shell but for me, this is the best and easy way to do the job.

Please if you have a better solution let me know I’m willing to learn new ways and do it in a better way.

Update

The best solution is just use the fallowing command to switch

Top comments (5)

You aren’t actually making it a default shell, your shell is still /usr/bin/bash . You are just executing a ZSH framework on top of bash shell and the only environment where it makes sense is Cygwin on Windows. On all other operating systems you’d be better off by actually making it your default login shell with a standard chsh command chsh -s $(which zsh) . It’s even easier, isn’t it? And won’t bite you back if you’re developing shell scripts.

4 likes Like Comment button

Always ask questions to feed the curiosity and learn something new on the way. El respeto al derecho ajeno es la paz. Benito Juarez Garcia.

Thank you for the information and for the better solution I really appreciated.
Yeah, you are right it is better to make it the default login shell.

I’m not developing scripts for now, but like you said you never know in the future right.

4 likes Like Comment button

Источник

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