首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >$PATH不更新

$PATH不更新
EN

Unix & Linux用户
提问于 2020-09-19 04:54:14
回答 1查看 6K关注 0票数 3

我意外地在我的Ubuntu机器上删除了我的~/.bashrc,现在每当我在终端上输入一个命令时,它就给了我这个错误:

代码语言:javascript
复制
The command could not be located because '/usr/bin:/bin' is not included in the PATH environment variable.

我尝试将export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin添加到~/.bashrc中,但我仍然面临着同样的问题。

我可以在终端上使用export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin,它可以正常工作,但每次打开新终端时,我都必须手动操作。有什么解决办法吗?

~/..bashrc目录:

代码语言:javascript
复制
case $- in
    *i*) ;;
      *) return;;
esac
HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000
shopt -s checkwinsize
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac
if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'
    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
export POCL_DEBUG=0
export POCL_DEVICES=rsim
export POCL_CACHE_DIR=$HOME/temp_pocl
export REDEFINE_HOME=$HOME/redefine/
export POCL_LEAVE_KERNEL_COMPILER_TEMP_FILES=1
export PATH=$PATH:/home/harry/redefine/bin/riscv32-gcc/bin
export LLVM_PATH=$HOME/llvm-project/build/bin
export PATH=$HOME:$LLVM_PATH
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2020-09-19 10:00:34

首先,您应该从PATH中删除您的~/.bashrc声明。您不希望每次打开新外壳时都重新运行这些程序!这类全局变量定义为属于 ~/.profile,如果文件存在,则定义~/.bash_profile

现在,您所面临的问题是由您拥有的多路径声明造成的,这些声明正在相互覆盖。以下是相关的内容:

代码语言:javascript
复制
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
export PATH="$PATH":/home/harry/redefine/bin/riscv32-gcc/bin
export LLVM_PATH="$HOME"/llvm-project/build/bin
export PATH="$HOME:$LLVM_PATH"

这是4个命令,每个命令都将按顺序运行。让我们看看如果我们在终端中运行它们会发生什么:

代码语言:javascript
复制
$ export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
$ echo "$PATH"
/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
$ export PATH="$PATH":/home/harry/redefine/bin/riscv32-gcc/bin
$ echo "$PATH"
/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/home/harry/redefine/bin/riscv32-gcc/bin
$ export LLVM_PATH="$HOME"/llvm-project/build/bin
$ export PATH="$HOME:$LLVM_PATH"
$ echo "$PATH"
/home/terdon:/home/terdon/llvm-project/build/bin

正如您在上面看到的,您的最后一个export命令覆盖了您以前所做的更改,并将PATH设置为只包含您的$HOME dir (这没有意义,您不希望您的$HOME在您的路径中!)还有你的$LLVM_PATH。您想要做的是将$LLVM_PATH添加到$PATH中,因此您应该拥有以下内容:

代码语言:javascript
复制
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/home/harry/redefine/bin/riscv32-gcc/bin
export LLVM_PATH="$HOME"/llvm-project/build/bin
export PATH="$PATH:$LLVM_PATH"

因此,从您的PATH中删除所有的~/.bashrc定义,然后将上面的三行添加到~/.profile中。

票数 4
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/610179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档