Score:1

"Command not found" errors from terminal, even though the software is installed

ru flag

I know ubuntu comes with a gnome-terminal. A few days ago, I started to face a new issue that I can't describe. I use the vscode code editor in my daily life. Many commands, like npm,pnpm, yarn, rust -v etc., are not working in the gnome-terminal, and I'm config everything with my .bashrc file with the same user name. Im also uses another terminal app like hyper, and all command does not work. It shows an error that looks like

// 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 <deb name>
rajdeepsingh@officialrajdeepsingh:~$

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

Hyper terminal hyper terminal app


gnome-terminal gnome terminal


But all commands work fine with the vscode terminal. I can't find a solution yet. vscode

my bashrc file configuration look like

# ~/.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 command output

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/@[email protected]/node_modules/@pnpm/exe/node_modules/.bin/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/@[email protected]/node_modules/@pnpm/exe/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/@[email protected]/node_modules/@pnpm/linux-x64/node_modules/.bin/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/@[email protected]/node_modules/@pnpm/linux-x64/pnpm
/home/rajdeepsingh/.local/share/pnpm/global/5/.pnpm/node_modules/.bin/pnpm
/home/rajdeepsingh/.local/share/pnpm/pnpm

ru flag
It's likely these items are in a location not in your `PATH`. What does `sudo find / -type f -iname 'pnpm'` return on the command line? it's likely that these binaries are NOT in a location defined in your PATH.
officialrajdeepsingh avatar
ru flag
@ThomasWard I run the `sudo find / -type f -iname 'pnpm'` command in my system, and I add the `sudo find / -type f -iname 'pnpm'` output in the question description. I do not have any video about `sudo find / -type f -iname 'pnpm'` command. You can check the command output in the question description and tell me what happens with the ubuntu system.
ru flag
Do me a favor then - open the terminal and run `echo $PATH`. Make sure that `/home/rajdeepsingh/.local/share/pnpm` shows in there (this is just one of several paths you append). We need to make sure that your terminal shell (Bash usually by default) is in fact seeing the PATHs
officialrajdeepsingh avatar
ru flag
@ThomasWard `echo $PATH` show following output `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin` i think some problem with my bashrc file related to the PATH variable.`
Score:1
us flag

Even if you managed to resolve this, I'd like to suggest trying to understand what is actually going on here a bit better. First, let's go back to your original error message:

Command 'pnpm' not found

The reason this happens is that your shell (probably bash) cannot find the pnpm binary anywhere it's told to look. So where is it told to look? You can find this out by simply having a look at what's in your $PATH variable:

echo $PATH

A relatively normal output may look something like:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/var/lib/snapd/snap/bin:/root/bin

This is a colon separated list of "places to look", so the reason you can simply write ls in your terminal for example is that bash knows to look for it, and finds it, in one of those folders. If you want to know where bash finds ls, you can do:

# whereis ls
ls: /usr/bin/ls (...)

So, if I were you, I would try to figure out:

  1. What do you actually want to happen when you type pnpm, where is that binary located?
  2. Ensure that the directory where that binary is located is a part of your $PATH variable

Based on the output provided in your question, I'm going to assume you want pnpm to mean /home/rajdeepsingh/.local/share/pnpm/pnpm. First, you can test this by running the binary with its full path, like:

$ /home/rajdeepsingh/.local/share/pnpm/pnpm

As you mentioned in your comment, is location is not in your PATH, which explains why bash doesn't know how to find the binary:

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

This path looks not only completely different, it has nothing from your .bashrc. So what's happening? Why are you forced to specify -i for interactive mode?

Well, you have this in your .bashrc:

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

I have no idea why you have this, because it's not a part of any standard .bashrc that I know of. A basic standard example could look like:

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

So, the reason you have to run bash -i is not because "that's how it works", it's because you yourself (or someone else) have added a constraint into .bashrc that simply exits if you are not running bash -i.

My suggestion to you: start over. Create a new .bashrc and set things up exactly as you want them, because it's not complicated, but you're making it very complicated.

Your .bashrc could probably look like this:

# 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

Try that, then source ~/.bashrc then echo $PATH.

officialrajdeepsingh avatar
ru flag
Thank you for the guidance; I can try and update the answer on StackOverflow.
pzkpfw avatar
us flag
@officialrajdeepsingh it's up to you, all I wanted was to provide some more context on what's actually happening. It's usually good in the long term to also understand *why* something works (or doesn't work)
Score:0
ru flag

Everything is fine in the terminal and with the .bashrc file. But my terminal does not run using a bash interpreter. So I config manually in gnome-terminal and hyper-terminal.

Hyper-terminal solution


// hyper.js

shell: "",

shellArgs: ['-i'],

gnome-terminal solution You can add a bash interpreter in gnome-terminal with a custom command. You can use bash or `bash -i'; both work fine.
gnome terminal

pzkpfw avatar
us flag
I’m curious why this would be needed for gnome-terminal. What shell do you have listed in passwd?
pzkpfw avatar
us flag
I also don’t understand why you would have to force bash to run an interactive shell. This is all very strange and I have a feeling you’re trying out a lot of stuff without understanding why you’re doing it.
officialrajdeepsingh avatar
ru flag
Yes, @pzkpfw, I tried lots of stuff to solve my problem and spent ten days trying to solve this error on the internet. I did not find a similar question. Bash is a default interactive when I run the `passwd` command. Then I study, read gnome-terminal docs, read more about the bashrc file, and run simple bash commands in the terminal and everything is fine. All my commands, like npm deno, etc., work fine.
officialrajdeepsingh avatar
ru flag
I do not know if it is the right approach or not. But I work. Then I use the custom command property in gnome-terminal and hyper-terminal. Now I use custom command property to force gnome-terminal to use bash interpreter.
pzkpfw avatar
us flag
I've added an answer, hopefully it's of some help.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.