Bash: app definitely on $path, but not found when run - python-3.x

I'm having a issue with a python app that I installed on a empty server.
The package I installed is invoke using pip3 install invoke
After install if I just run invoke without specifying the abs path, then I
get a error: -bash: /usr/bin/invoke: No such file or directory
Running it with the full path to the app works fine.
So I'm confused why it's ignoring the legit app that is in a location
that is definitely on the $PATH.
See the cli commands below for visual reference:
/# invoke
-bash: /usr/bin/invoke: No such file or directory
/# find -name invoke
./usr/local/bin/invoke
./usr/local/lib/python3.6/dist-packages/invoke
/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
/# /usr/local/bin/invoke -V
Invoke 1.4.1
Anyone know what's going on here?

As mentioned in the comments of my original post, this was because the command was previously hashed and bash remembered the old path. Running hash -r was suggested, which resets all mappings. I eventually used hash -d invoke which cleared only that single entry. My reasoning was that I wasn't sure if anything else in the mappings were expected to be there by some other app.
Edit: As pointed out in the comments below, there is no harm in using -r since it's just a faster way to look something up and is saved there once it finds it again anyway.

Related

How to reset the $PATH?

I confess, I very don't know what I'm talking about.
This morning I wanted to install Javascripting (to learn javascript) on my Mac, so I watch a video to do it:
I downloaded node.js and I installed it;
after that I opened the terminal and I type: npm install -g javascripting and here I've got some errors. I tried to search the solution but I think I created a big problem:
Basically I modified the $PATH several times and now the situation is this.
If I run echo PATH it displays
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I wanted to clean it all so I tried to type:
brew uninstall --force node
but the terminal says:
zsh: command not found: brew
I can't do anything.
Please, someone help me :(
If you just want to clear this environment variable, just do 'unset PATH'.
But, be aware that PATH is used by a shell (i.e. bash, ksh, zsh...) to look for programs in these directories. clearing it has side effects.
The 'brew' program is somewhere, to find it, you could use the following command :
find / -name 'brew' -print
It can take a little while to find it.
Either use that found path, or add the directory where that program is found to the PATH variable, as in
PATH=$PATH:/location_of_brew_program; export PATH

How do I run man without using sudo and not under root directory?

I've encountered a problem that I can't seem to find a solution for. Running the man command anywhere that isn't in ~ or without using sudo returns:
"/usr/bin/man: can't execute less: Invalid argument
/usr/bin/man: command exited with status 255: ..."
I've tried running export MANPAGER=less
$PAGER and $MANPAGER are set to less. It still does not seem to work.
What do I do?
Edit:
After further review I've noticed that the command works everywhere except a mounted network directory that I use. I can use less and echoman ls`` just fine, but just using man as usual brings up the mentioned issue.
Try to change the permission and ownership of /usr/bin/man. Make it so that it is executable by everyone.

Where is the `sdk` command installed for sdkman

I just installed sdkman for installing grails on my machine (MacOS). When I run which sdk command I don't get any output. But when I run the sdk help command the shell is able to resolve it and give the right output. I checked all the directories mentioned in $PATH environment variable but I could not find any executable sdk. So my question is how is shell able to resolve the sdk command?
Note: I also checked in Ubuntu and I see the same behavior.
As you mentioned correctly "sdk" is not a command, its a declared function created by sdkman-main.sh (in ~/.sdkman/src) once called from ~/.sdkman/bin/sdkman-init.sh
This is the reason why the installation page of sdkman asks for appending the following steps in the .bash_profile which declares this function each time the bash profile is loaded :
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
[[ -s "/home/dudette/.sdkman/bin/sdkman-init.sh" ]] && source "/home/dudette/.sdkman/bin/sdkman-init.sh"
This is also the reason "which" command doesn't pick it up as it checks for the installed commands on the linux PATH
OK. So I found it out. As #that-other-guy mentioned in the comment above, I used type -a instead of which, which showed me that it was a function defined.

How to change default directory for a command in Bash?

Firstly, I am new to Linux so excuse me if any terminology is wrong; I'll try to phrase the problem as competently as possible.
I have installed Ruby (2.4.0) via Linuxbrew. The ruby command works fine; it installed correctly. However, when I try to use the gem command (which Ruby should have installed) I receive this error:
bash: /usr/bin/gem: No such file or directory
Now, because I installed this with Linuxbrew I know that this directory isn't correct. For example:
result of which gem : /home/me/.linuxbrew/bin/gem
result of which ruby : /home/me/.linuxbrew/bin/ruby
Therefore, it seems gem is installed but the gem command isn't linked to the correct path. I assume I need to direct the gem command to the path of which gem as opposed to /usr/bin/gem that bash is saying doesn't exist. How would I go about changing this? I tried in vain to change the bash_profile but I'm not sure what to do.
Again, excuse me if ruby and gem are not referred to as commands and if the problem isn't the "default directory" as stated in the title. I wasn't sure how to label it.
EDIT/TL;DR:
Basically, how can I make gem execute this: /home/me/.linuxbrew/bin/gem instead of looking for the program in /usr/bin/gem?
Instead of running gem, run /home/me/.linuxbrew/bin/gem, i.e. type the full path name (followed by any arguments you may need).
If this becomes too tiresome, you could change your PATH. Prepend your bin directory with
PATH=$HOME/.linuxbrew/bin:$PATH
First, the reason you get the error /usr/bin/gem not found, is that earlier in the same shell session, the file used to be there. Bash will cache this to speed things up when running the same command many times. Running hash -r will clear this.
Editing PATH you seem to have managed, hence the which command gives the result it does.
To answer my own question-
As I had previously installed and uninstalled Ruby via apt-get instead of Linuxbrew in the same Terminal window, Bash was looking for gem in usr/bin as opposed to the path specified in my bash_profile to Linuxbrew.
Therefore, Stian's answer above with hash -r would also work, I am sure.

Modifying $PATH variable

Trying to install node.js.
Did brew install node
It seems to have worked.
However, received this message upon its completion
Homebrew installed npm.
We recommend prepending the following path to your PATH environment
variable to have npm-installed binaries picked up:
/usr/local/share/npm/bin
Ok ... so, I open my bash_profile...
And this is what I have in it:
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Trying to understand how to modify it correctly so I won't ruin it ...
Do I add /usr/local/share/npm/bin like this
export PATH="/usr/local/bin:/usr/local/sbin:~/bin/usr/local/share/npm/bin:$PATH"
If not, what is the correct way to add that path?
Thank you for any help provided!
PS. let me know if there is any additional information I could have provided
EDIT
upon seeing which npm in macedigital's answer, I ran that ...
and got this: /usr/local/bin/npm
and that was before I did the second answer (ie, ThiefMaster's answer).
ran which npm again ...
and got the same answer as before ...
i did echo $PATH and got this:
/Users/name/.rvm/gems/ruby-1.9.3-p374/bin:/Users/name/.rvm/gems/ruby-1.9.3-p374#global/bin:/Users/name/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/name/.rvm/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin
So, it looks like I already had it installed?
Therefore, how do I handle the answers? I hate leaving it unresolved since both of you were so helpful and I feel bad that I asked without providing echo $PATH information since that would have told you that I had it installed ...
EDIT 2
ls -la /usr/local/share/npm/bin gets this:
ls: /usr/local/share/npm/bin: No such file or directory
which -a npm gets this: /usr/local/bin/npm
EDIT 3
ls -a /usr/local/bin/npm gets this: /usr/local/bin/npm
there's no timestamp...
Short answer, do this (notice the additional colon I inserted):
export PATH="/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
The $PATH environment variable is colon separated list of directories to look in if you want to run a command without a fully qualified path (e.g. running npm instead of having to type /usr/local/share/npm/bin/npm).
You can try this from a terminal before actually saving the change in bash_profile. If everything is good, which -a npm will show you all fully qualified path(s).
UPDATE
It is not necessary to modify the $PATH variable in order to use npm. What homebrew install recommends instead is to add the directory where npm-installed binaries are stored to the $PATH variables, so its more convenient to use them from the command line later on.
Node modules like phantomjs, phonegap, express, etc. provide binaries which after the change are available on the command prompt without having to type the full path.
The cleanest solution is adding the following between the two lines you posted:
export PATH="/usr/local/share/npm/bin:$PATH"
That way everything stays readable and you prepend it to PATH just like the program suggested it. And if you ever want to undo the change you just remove that line instead of editing a possibly long line.
In PATH ORDER IS IMPORTANT. So anything before desired npm version will still cause problems.
#adding in first place of the path, before anything else
export PATH=/usr/local/bin:otherPathEntries:$PATH
assuming that version of npm You want is in /usr/local/bin, to check all use 'which -a npm'

Resources