如何解决“无法找到该命令,因为‘/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

相关内容