bash.bashrc 文件混乱,命令不再起作用

bash.bashrc 文件混乱,命令不再起作用

尝试安装 Java,我尝试使用以下行将其添加到可执行路径:

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

在系统范围的/etc/bash.bashrc文件中。

由于某种原因这不起作用,所以我使用了:

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

最初这似乎工作正常,除了现在sudo,,以及其他一切lsfind不再工作了。

然后我尝试删除这些行并重新启动系统,但该命令不可用;错误是:

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

/etc/environment为了解决这个问题,我复制了in的内容/etc/bash.bashrc,添加了该行export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_60/bin,然后键入source /etc/bash.bashrc.

同样,一切正常,但仅在单个终端窗口上运行,而不是在重新启动后运行。

我尝试了其他事情,目前最后/etc/bash.bashrc有几行:

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/

但我必须在所有终端窗口中输入source /etc/environmentandsource /etc/bash.bashrc才能获取java和 命令。就好像我的改变不是永久性的。

echo $PATH目前,在清晰的终端窗口中的结果是:

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

之后source /etc/environment就变成:

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

最终,在source /etc/bash.bashrc它之后:

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

完整的 bash.bashrc 文件:

# 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/

有人可以帮助我吗?我使用的是 Ubuntu 12.04 LTS

答案1

要将您恢复/etc/bash.bashrc到原始状态(如果您不记得那是什么),您可以执行以下操作:

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

否则@aprad046 的回答似乎是最好的解决方案。

答案2

尝试将 bash.bashrc 恢复为其默认设置,并在 ~/.bashrc 文件中编辑 PATH 的本地副本。换句话说,输入最后两行:

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/

在 ~/.bashrc 文件中而不是 /etc/bash.bashrc 中。您可能必须重新启动才能使更改生效。

如果这样有效,并且您仍然希望更改在系统范围内进行,则将 PATH 变量附加到 /etc/environment 中以获取 Java 路径。

答案3

最常用的命令(包括您尝试过的命令)位于 中/bin,因此您可以通过键入/bin/ls/bin/vi等来运行它们。

相关内容