I just setup bash v4.1.0 on my machine.

The old version is under /bin/bash. Is there a way to use the newer version of bash without replacing the old one from /bin? I want the newer version to be used as the default one

$ which bash
$ bash --version
GNU bash, version 3.00.15(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.
$ ~/bash/bash-4.1/bash --version
GNU bash, version 4.1.0(1)-release (i686-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

2 Answers 2


First of all, make sure your favorite bash is in $PATH before the system one. Also set the environment variable SHELL to the full path to your favorite interactive shell (presumably your own installed version of bash).

You can't set your own shell as login shell without root's intervention, but usually you don't need anything better than POSIX sh in ~/.profile anyway. You can put exec $SHELL at the end of ~/.profile so that you get your favorite interactive shell in console or ssh sessions, but make sure that you don't do it from shells that are not interactive (for example, some Linux distributions have X session scripts that start with #!/bin/bash --login). It is difficult to detect precisely when it is reasonable to call exec in .profile, but testing that the shell is interactive works in most cases; you can do something like this:

case $- in
  *i*) :;;
  *) exec "$SHELL";;

If you're not root, that's about all you can do. In particular, scripts headed #!/bin/bash will keep on using the system bash, while scripts headed #!/usr/bin/env bash will use yours.

If you are root, you can add your bash installation to /etc/shells, after which you can use chsh to change your login shell to it. You can also replace /bin/bash by your own version, but I wouldn't recommend this for such a critical system component. If you really want to replace /bin/bash, at least keep your package manager happy; on a dpkg-based system, you can use dpkg-divert.

  • please explain how to make sure that you don't do it from shells that are not interactive.
    – Lesmana
    Oct 25, 2010 at 9:24
  • @lesmana: done. There are a few oddball cases where exec is not safe even in an interactive shell (e.g. there's a bug in bash 2.0–2.04 where running exec sometimes makes it go into an infinite loop), but none that I think you're likely to encounter. Oct 27, 2010 at 23:21

You can set your user's default shell using the usermod command with the -s option (requires root-privileges):

sudo usermod -s /home/lazer/bash/bash-4.1/bash lazer
  • 2
    In addition: You can also use chsh
    – echox
    Oct 23, 2010 at 11:21
  • 1
    @echox: Actually you can't. chsh only allows you to switch to the shells listed in /etc/shells, so it doesn't work for shells you installed yourself (unless you add them to /etc/shells yourself, but then you need root access anyway and could just as well use usermod).
    – sepp2k
    Oct 23, 2010 at 13:56
  • Oh, I haven't thought of this. Yes, you are right.
    – echox
    Oct 23, 2010 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .