如何解決「無法找到指令,因為 '/bin:/usr/bin' 未包含在 PATH 環境變數中」錯誤?

如何解決「無法找到指令,因為 '/bin:/usr/bin' 未包含在 PATH 環境變數中」錯誤?

我已經安裝了 Ubuntu 20.04.3 LTS 並安裝了 Anaconda3,但由於出現一些問題,我不得不卸載 Anaconda3。我以 root 身分使用此命令從/home/user目錄中刪除了它:

# rm -f anaconda3

之後我遇到了以下問題:

$ sudo -s
# ls
Command 'ls' is available in the following places
 * /bin/ls
 * /usr/bin/ls
The command could not be located because '/bin:/usr/bin' is not included in the PATH environment variable.
ls: command not found

這是我的最後幾行.bashrc

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/thilipkumar/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/thilipkumar/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/thilipkumar/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/thilipkumar/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

echo path以下是普通用戶和 root的輸出:

~$ echo $PATH
/home/thilipkumar/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
~$ sudo -s
/home/thilipkumar# echo $PATH
/root/anaconda3/

誰能建議我下一步該怎麼做?

答案1

檢查root使用者的/root/.profile/root/.bashrc檔案以更正路徑設定錯誤的地方。

您也可以透過將對應文件複製/etc/skel/root.

答案2

請使用以下命令替換檔案路徑:

export PATH=$PATH:/usr/bin:/bin

此命令永久替換原始路徑。這是一個例子:

/$ nano .bashrc
Command 'nano' is available in the following places
 * /bin/nano
 * /usr/bin/nano
The command could not be located because '/usr/bin:/bin' is not included in the PATH environment variable.
nano: command not found
/$ export PATH=$PATH:/usr/bin:/bin
/$ ls
backups  bin  boot  cdrom  dev  etc  home  lib  lib32  lib64  libx32  lost+found
madhu  media  mnt  opt  proc  root  run  sbin  snap  srv  swapfile  sys
tmp  usr  var

相關內容