首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“命令未找到”错误来自终端,即使安装了该软件

“命令未找到”错误来自终端,即使安装了该软件
EN

Ask Ubuntu用户
提问于 2022-11-04 16:17:51
回答 2查看 1.8K关注 0票数 1

我知道ubuntu有个侏儒终端机。几天前,我开始面对一个我无法描述的新问题。我在日常生活中使用vscode代码编辑器。许多命令,如npm,pnpm,纱线,锈迹-v等,没有在gnome终端中工作,而且我用我的.bashrc文件用相同的用户名配置所有的东西。Im还使用另一个终端应用程序,如超级程序,所有的命令都不能工作。它显示了一个看起来像

代码语言:javascript
复制
// pnpm 
rajdeepsingh@officialrajdeepsingh:~$ pnpm -v
Command 'pnpm' not found, did you mean:
  command 'npm' from deb npm (8.5.1~ds-1)
Try: sudo apt install 
rajdeepsingh@officialrajdeepsingh:~$

// deno
rajdeepsingh@officialrajdeepsingh:~$ deno -v
Command 'deno' not found, but can be installed with:
sudo snap install deno
rajdeepsingh@officialrajdeepsingh:~$ 

Hyper终端

gnome-终端

But所有命令都可以在vscode终端上正常工作。我还找不到解决办法。

my bashrc文件配置看起来类似于

代码语言:javascript
复制
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples


# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# 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, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

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

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
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

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands. Use like so:
#   sleep 10; alert
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$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
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



. "$HOME/.cargo/env"

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"



# add bun config
BUN_INSTALL="/home/rajdeepsingh/.bun"
PATH="$BUN_INSTALL/bin:$PATH"


# add android  studio config
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:'/home/rajdeepsingh/Android/Sdk/platform-tools/'

# pnpm
export PNPM_HOME="/home/rajdeepsingh/.local/share/pnpm"
export PATH="$PNPM_HOME:$PATH"
# pnpm end

# Adding the deno config Manually add the directory to your $HOME/.bashrc (or similar)
export DENO_INSTALL="/home/rajdeepsingh/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
# Endding deno config

# surreadDB config start
export PATH=/home/rajdeepsingh/.surrealdb:$PATH
PATH=/home/rajdeepsingh/.surrealdb:$PATH
#  surrealDB config end



# add bin path for meson
 export PATH="/usr/local/bin:$PATH"

find命令输出

代码语言:javascript
复制
rajdeepsingh@officialrajdeepsingh:~$ sudo find / -type f -iname 'pnpm'
[sudo] password for rajdeepsingh: 
find: ‘/proc/15133/task/15133/net’: Invalid argument
find: ‘/proc/15133/net’: Invalid argument
find: ‘/proc/15146/task/15146/net’: Invalid argument
find: ‘/proc/15146/net’: Invalid argument
/tmp/tmp.IUj8SI8GhN/pnpm
/var/lib/docker/overlay2/02f58b453f8130db2dbb34489e2af94785d03602b43ef2ad0307e0d325c69669/diff/tmp/tmp.Ql1W7VIpZc/pnpm
/var/lib/docker/overlay2/02f58b453f8130db2dbb34489e2af94785d03602b43ef2ad0307e0d325c69669/diff/tmp/tmp.AStX5DdonL/pnpm
/var/lib/docker/overlay2/02f58b453f8130db2dbb34489e2af94785d03602b43ef2ad0307e0d325c69669/diff/root/.local/share/pnpm/pnpm
/var/lib/docker/overlay2/3f7b1a6a85187fd302f284d25a747fd2cacaee2b524223c962903e126638e157/diff/usr/local/lib/node_modules/corepack/shims/nodewin/pnpm
/var/lib/docker/overlay2/3f7b1a6a85187fd302f284d25a747fd2cacaee2b524223c962903e126638e157/diff/usr/local/lib/node_modules/corepack/shims/pnpm
/var/lib/docker/overlay2/6c8ce272d3f69240c3cb6f2b1b2fddc9c7e2b0e1dd891ac4be300d54137a5044/diff/tmp/tmp.WZQjSag9fK/pnpm
/var/lib/docker/overlay2/6c8ce272d3f69240c3cb6f2b1b2fddc9c7e2b0e1dd891ac4be300d54137a5044/diff/root/.local/share/pnpm/pnpm
/var/lib/flatpak/app/org.gnome.Builder/x86_64/stable/273caab574876b514a20e1ef86fe6e17d507f2d7e72ef3bbd02a3dc696aa8851/files/lib/node_modules/corepack/shims/nodewin/pnpm
/var/lib/flatpak/app/org.gnome.Builder/x86_64/stable/273caab574876b514a20e1ef86fe6e17d507f2d7e72ef3bbd02a3dc696aa8851/files/lib/node_modules/corepack/shims/pnpm
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/home/rajdeepsingh/.local/share/pnpm/nodejs/16.17.0/lib/node_modules/corepack/shims/nodewin/pnpm
/home/rajdeepsingh/.local/share/pnpm/nodejs/16.17.0/lib/node_modules/corepack/shims/pnpm
/home/rajdeepsingh/.local/share/pnpm/nodejs/14.20.0/lib/node_modules/corepack/shims/nodewin/pnpm
/home/rajdeepsingh/.local/share/pnpm/nodejs/14.20.0/lib/node_modules/corepack/shims/pnpm
/home/rajdeepsingh/.local/share/pnpm/nodejs/16.17.1/lib/node_modules/corepack/shims/nodewin/pnpm
/home/rajdeepsingh/.local/share/pnpm/nodejs/16.17.1/lib/node_modules/corepack/shims/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/@pnpm+exe@7.13.1/node_modules/@pnpm/exe/node_modules/.bin/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/@pnpm+exe@7.13.1/node_modules/@pnpm/exe/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/@pnpm+linux-x64@7.13.1/node_modules/@pnpm/linux-x64/node_modules/.bin/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/@pnpm+linux-x64@7.13.1/node_modules/@pnpm/linux-x64/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/node_modules/.bin/pnpm
/home/rajdeepsingh/.local/share/pnpm/pnpm
EN

回答 2

Ask Ubuntu用户

发布于 2022-11-05 11:48:53

即使你设法解决了这个问题,我还是建议你试着更好地理解到底发生了什么。首先,让我们回到原来的错误消息:

代码语言:javascript
复制
Command 'pnpm' not found

之所以会发生这种情况,是因为您的shell (可能是bash)在它要查看的任何地方都找不到pnpm二进制文件。那么它要去哪里看呢?只要简单地查看一下$PATH变量中的内容,就可以发现这一点:

代码语言:javascript
复制
echo $PATH

相对正常的输出可能如下所示:

代码语言:javascript
复制
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/var/lib/snapd/snap/bin:/root/bin

这是一个冒号分隔的“查找位置”列表,因此您可以简单地在终端中编写ls的原因是bash知道查找它,并在其中一个文件夹中找到它。如果您想知道bash在哪里找到ls,可以这样做:

代码语言:javascript
复制
# whereis ls
ls: /usr/bin/ls (...)

所以,如果我是你,我会努力弄清楚:

  1. 当您键入pnpm时,您实际上想要发生什么,二进制文件位于哪里?
  2. 确保该二进制文件所在的目录是$PATH变量的一部分。

根据问题中提供的输出,我将假设您希望pnpm的意思是/home/rajdeepsingh/.local/share/pnpm/pnpm。首先,您可以通过运行包含完整路径的二进制文件来测试它,如下所示:

代码语言:javascript
复制
$ /home/rajdeepsingh/.local/share/pnpm/pnpm

正如您在注释中提到的,路径中的位置是而不是,这解释了bash不知道如何找到二进制文件的原因:

代码语言:javascript
复制
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

这个路径不仅看起来与.bashrc完全不同,而且它与您的没有任何。那发生什么事了?为什么您被迫为交互模式指定-i

好吧,在您的.bashrc中有以下内容:

代码语言:javascript
复制
# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

我不知道为什么会出现这种情况,因为据我所知,它不是任何标准.bashrc的一部分。一个基本的标准示例可能如下所示:

代码语言:javascript
复制
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

所以,您必须运行bash -i的原因并不是因为“这就是它的工作方式”,而是因为您自己(或其他人)在.bashrc中添加了一个约束,如果您不运行bash -i,它就会退出。

我对你的建议是:重新开始。创建一个新的.bashrc,并按照您的需要设置它们,因为它并不复杂,但是您正在使它变得非常复杂。

您的.bashrc 可以,可能如下所示:

代码语言:javascript
复制
# Source global definitions (system-wide)
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment (default)
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

#( *** your config here, not related to PATH *** )

export PATH=$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH
export PATH=/home/rajdeepsingh/.bun/bin:$PATH
export PATH=$PATH:$HOME/Android/Sdk/tools
export PATH=$PATH:/home/rajdeepsingh/Android/Sdk/platform-tools/
export PATH=/home/rajdeepsingh/.local/share/pnpm:$PATH
export PATH=/home/rajdeepsingh/.deno/bin:$PATH
export PATH=/home/rajdeepsingh/.surrealdb:$PATH

# export PATH="/usr/local/bin:$PATH" <- pointless, /usr/local/bin is part of
#                                       any normal path definition

试试,然后是source ~/.bashrc,然后是echo $PATH

票数 1
EN

Ask Ubuntu用户

发布于 2022-11-05 07:52:55

终端和.bashrc文件中的一切都很好。但是我的终端不使用bash解释器运行。所以我在gnome终端和超级终端中手动配置。

超终端解决方案

代码语言:javascript
复制
// hyper.js

shell: "",

shellArgs: ['-i'],

gnome终端解决方案您可以使用自定义命令在gnome终端中添加bash解释器。您可以使用bash或“both”;两者都工作得很好。

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

https://askubuntu.com/questions/1439097

复制
相关文章

相似问题

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