3

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

  • It's kind of hard to follow what happened here. Could you please edit your question and add your current /etc/bash.bashrc? Also, a broken $PATH is not a big deal. If a command is not in your $PATH, you can always run it using its full path. For example, instead of sudo, run /usr/bin/sudo. – terdon Jul 1 '14 at 16:50
  • i followed your suggestion. is there a way to have a clean bash.bashrc file? maybe that would work – FN11 Jul 1 '14 at 17:20
  • Set PATH in /etc/profile or /etc/environment or a bunch of other places… but not bashrc. – Gilles 'SO- stop being evil' Jul 1 '14 at 23:39
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.

| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.