Messed up bash.bashrc file, commands not working anymore

19,314

Solution 1

Try restoring bash.bashrc to its default setting, and edit your local copy of PATH in your ~/.bashrc file instead. In other words, put those last two lines:

export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_60/bin/
export JAVA_HOME=$JAVA_HOME:/usr/lib/jvm/jdk1.7.0_60/bin/java/

in your ~/.bashrc file instead of /etc/bash.bashrc. You might have to restart for changes to take place.

If that works, and you still want the changes to be system-wide, then append the PATH variable in /etc/environment to have the Java path.

Solution 2

To restore your /etc/bash.bashrc to its original state (if you can't remember what that is), you can do:

sudo rm /etc/bash.bashrc
sudo apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall bash

Otherwise @aprad046's answer seems like the best solution.

Share:
19,314

Related videos on Youtube

FN11
Author by

FN11

Updated on September 18, 2022

Comments

  • FN11
    FN11 over 1 year

    Trying installing Java, I tried to add it to the executable path with the line:

        export PATH=/usr/lib/jvm/jdk1.7.0_60/bin:$PATH
    

    in the system-wide /etc/bash.bashrc file.

    For some reason this wasn't working, so I used:

    JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    export JAVA_HOME
    export JRE_HOME
    export PATH
    

    Initially this seemed to work fine, except that now sudo, ls, find and everything else aren't working anymore.

    I then tried to erase those lines and restart the system but the command weren't available; the errors are:

    Command 'sudo' is available in '/usr/bin/sudo'
    The command could not be located because '/usr/bin' is not included in the PATH  environment variable.
    sudo: command not found
    

    To fix this I copied the content of /etc/environment in /etc/bash.bashrc, added the line export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_60/bin and then typed source /etc/bash.bashrc.

    Again, everything was working, but only on a single terminal window and not after a restart.

    I tried other things and currently at the end of /etc/bash.bashrc there are the lines:

    export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_60/bin/
    export JAVA_HOME=$JAVA_HOME:/usr/lib/jvm/jdk1.7.0_60/bin/java/
    

    But I have to type source /etc/environment and source /etc/bash.bashrc in all terminal windows to get both java and the commands. It's like my changes aren't permanent.

    Currently the result of echo $PATH in a clear terminal window is:

    /usr/lib/jvm/jdk1.7.0_60/bin/
    

    after source /etc/environment it becomes:

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    

    and eventually, after source /etc/bash.bashrc it is:

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/jdk1.7.0_60/bin/
    

    Full bash.bashrc file:

    # System-wide .bashrc file for interactive bash(1) shells.
    
    # To enable the settings / commands in this file for login shells as well,
    # this file has to be sourced in /etc/profile.
    
    # If not running interactively, don't do anything
    [ -z "$PS1" ] && return
    
    # check the window size after each command and, if necessary,
    # update the values of LINES and COLUMNS.
    shopt -s checkwinsize
    
    # set variable identifying the chroot you work in (used in the prompt below)
    if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
        debian_chroot=$(cat /etc/debian_chroot)
    fi
    
    # set a fancy prompt (non-color, overwrite the one in /etc/profile)
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    
    # Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
    # If this is an xterm set the title to user@host:dir
    #case "$TERM" in
    #xterm*|rxvt*)
    #    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    #    ;;
    #*)
    #    ;;
    #esac
    
    # enable bash completion in interactive shells
    #if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    #    . /etc/bash_completion
    #fi
    
    # sudo hint
    if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; then
        case " $(groups) " in *\ admin\ *)
        if [ -x /usr/bin/sudo ]; then
            cat <<-EOF
            To run a command as administrator (user "root"), use "sudo <command>".
            See "man sudo_root" for details.
    
            EOF
       fi
       esac
    fi
    
    # if the command-not-found package is installed, use it
    if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
        function command_not_found_handle {
                # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
                    /usr/bin/python /usr/lib/command-not-found -- "$1"
                    return $?
                elif [ -x /usr/share/command-not-found/command-not-found ]; then
                    /usr/bin/python /usr/share/command-not-found/command-not-found -- "$1"
                   return $?
            else
               printf "%s: command not found\n" "$1" >&2
               return 127
            fi
        }
    fi
    
    export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_60/bin/
    export JAVA_HOME=$JAVA_HOME:/usr/lib/jvm/jdk1.7.0_60/bin/java/
    

    Anyone can help me? I'm under Ubuntu 12.04 LTS

    • FN11
      FN11 almost 10 years
      i followed your suggestion. is there a way to have a clean bash.bashrc file? maybe that would work
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' almost 10 years
      Set PATH in /etc/profile or /etc/environment or a bunch of other places… but not bashrc.
  • SuperSandro2000
    SuperSandro2000 over 2 years
    Thank you so much for the confmiss option!