Path, /usr/bin/ and /usr/local/bin/ - linux

I installed watchr on OS X (10.8.3) using gem install watchr. And it's installed in /usr/bin/watchr
$ which watchr
/usr/bin/watchr
However, when I tried to call it $ watchr -v, the system couldn't find it.
$ watchr -v
-bash: /usr/local/bin/watchr: No such file or directory
I think this is related to how the path is set up on my machine. My questions:
What is the right way to fix it?
In general, what programs should go to /usr/bin/ vs. /usr/local/bin/?
When I do e.g. $ /usr/bin/watchr -e 'watch(./hello.txt) ...', are we looking at the hello.txt in the current directory or in /usr/bin/ i.e. the same directory as watchr?

The path to your command was cached with a bad value. Try to update the cached directory that bash has stored for the path.
hash -d watchr
I found the answer over here which ctags shows /usr/local/bin/ctags but when I run ctags it runs /usr/bin/ctags. How is this possible?

Is /usr/local/bin/watchr a broken symlink? That would make which watchr not include it but watchr would print this error:
-bash: /usr/local/bin/watchr: No such file or directory
I don't know why the gem that comes with OS X installs programs in /usr/bin/, but generally /usr/bin/ is meant for preinstalled programs, and package managers use something like /opt/local/bin/ or /usr/local/bin/.
I also have /usr/local/bin/ before other folders on the path, and I put most programs that I install or compile manually to /usr/local/bin/. I used to have a separate ~/bin/ folder, but it's easy to find non-Homebrew programs with something like find /usr/local/bin ! -lname '../Cellar/*'.
Related questions about /usr/local/bin/ in general:
https://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux
https://unix.stackexchange.com/questions/4186/what-is-usr-local-bin-came-across-it-in-an-script-installation-for-applescript

create a file called .profile in your home directory and add the following line.
export PATH=“/usr/local/bin:/usr/local/sbin:/usr/bin:$PATH”

Related

How do I move files out of a broken directory in linux?

I know the premise of the question may be confusing, but I want to understand what happened.
Recently I have been experimenting with the rockchip OK3399 single-chip computer(see here) and have installed a linux system on it with TF card installation. Using Putty and connecting with serial protocol, I was able to establish a connection with the OK3399 computer and control it through my laptop.
I am trying to self-learn some linux with the OK3399 system. I created a bash code by the name of displayvids.sh inside the directory /usr/bin, which is meant to take a variable number of pictures with a mipi camera and then save in a directory for work.
I finished writing the code, but for some reason I cannot run the .sh file when my working directory is not the /usr/bin directory, despite /usr/bin being in the %PATH% environment variable. So, I executed the following command:
mv /usr/bin/display* /usr/local/bin
... attempting to move the file to /usr/local/bin instead. The command ran successfully, but when I tried to run the command:
cd /usr/local/bin
It tells me that I cannot cd to bin
As seen from the above image, the /usr/local/bin is not even a directory. Why would mv succeed if the target was not a directory? How can I retrieve my bash file?
Why would mv succeed if the target was not a directory?
mv can also rename files:
mv foo.txt bar.txt
You renamed your script to bin and moved it under /usr/local.
You may want to remember to add a trailing slash next time, to have mv barf if the target isn't a directory:
mv /usr/bin/display* /usr/local/bin/
How can I retrieve my bash file?
Rename it back.
mv bin displayvids.sh
For future reference, you can use the file command to (try to) identify the contents of a file, if it's installed:
file bin
would have probably said bin: Bash script or similar.

How to use nvim command if neovim is installed using appimage?

I have installed nvim using AppImage mentioned as below
curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage
chmod u+x nvim.appimage
./nvim.appimage
if i use nvim test,yml ,it fails as '-bash: /usr/bin/nvim: No such file or directory'
if i use ./nvim.appimage test.yml then it works. How to map this to nvim so that it works properly?
Linux looks for binaries in the paths that are set in $PATH variable. To check current paths execute echo $PATH
One way to fix it would be to move nvim.appimage (and rename it to just nvim) to one of the paths set in that variable.
Another way is to append the current path of nvim.appimage to $PATH. This was answered in detail How to correctly add a path to PATH?

Wrong executable path for python in linux

In linux bash, I need to run an application (HTSeq) which uses python. When I run the command I get this error:
-bash: /app/HTSeq-0.5.3p7/bin/htseq-count: /usr/bin/python26: bad interpreter: No such file or directory
The thing is that I do not have "python26" in my executable path. So in my /usr/bin/ path I have followings:
/usr/bin/python2.6
/usr/bin/python
I think sometimes I have manually changed something incorrectly. But how can I fix it?
Thanks in advance.
Try renaming "python2.6" to "python26" with sudo mv /usr/bin/python2.6 /usr/bin/python26
Well, since you don't have sudo rights, you could try this:
First create a symlink,
ln -s /usr/bin/python2.6 ~/Desktop/python26
and then adding the symlink dir to your PATH variable
export PATH=$PATH:/home/<your account>/Desktop

Cygwin path to /cygdrive/C/Program Files (x86)/GnuWin32 directory?

I am having trouble executing a program located in the "C:\Program Files (x86) directory in Windows from within Cygwin. Anyone know the trick to getting this to work?
jboss#QA024 /cygdrive/C/jboss/EAP-6.0.1/jboss-eap-6.0/bin
$ wgetexe="/cygdrive/C/Program Files (x86)/GnuWin32/wget.exe --help"
jboss#QA024 /cygdrive/C/jboss/EAP-6.0.1/jboss-eap-6.0/bin
$ bash $wgetexe
bash: /cygdrive/C/Program: No such file or directory
jboss#QA024 /cygdrive/C/jboss/EAP-6.0.1/jboss-eap-6.0/bin
$ bash "$wgetexe"
bash: /cygdrive/C/Program Files (x86)/GnuWin32/wget.exe --help: No such file or directory
Try this:
wgetexe="/cygdrive/C/Program Files (x86)/GnuWin32/wget.exe"
"$wgetexe" --help
Since it's an executable, you don't want to pass it as an argument to bash, which will try to execute it as a script. Since it has spaces in the path name, you need to quote the name so the shell doesn't try to execute cygdrive/C/Program with invalid arguments.
You should also be able to add the directory to your $PATH:
PATH="$PATH:/cygdrive/C/Program Files (x86)/GnuWin32"
Keep in mind that GnuWin32 programs are Windows executables, and any file paths they use will be interpreted using Windows syntax. Cywin executables (anything that uses cygwin1.dll) use Cygwin path syntax.
Better yet, install the Cygwin version of wget and just invoke it as wget --help.
For example, if you're using the GnuWin32 wget, you might use:
wget -O "C:\cygwin\home\yourname\output-file" "$url"
whereas with the Cygwin wget you might use:
wget -O "/home/yourname/output-file" "$url"
I've always found it easiest to use Cygwin executables from Cygwin whenever possible.
Try this, it always worked or me.
wgetexe="/cygdrive/C/Program\ Files\ \(x86)/GnuWin32/wget.exe"
"$wgetexe" --help

How can I prevent finding executable on $PATH?

I am using a system with an incomplete installation of GNAT, the GNU Ada compiler. A script (in the gdb testsuite) is finding /usr/bin/gnatmake and assumes that it can run Ada compiles. These fail because a the linker can't find libgnat.so.
I don't have root access, so I can't install libgnat.so or remove /usr/bin/gnatmake.
Is there any way to prevent a script from finding gnatmake in /usr/bin? I clearly cannot remove /usr/bin from the path.
Can you install a private, working version of gnatmake?
If you can, then you can create a symlink to the working version of gnatmake in your $HOME/bin directory:
ln -s /path/to/real/gnatmake ~/bin/gnatmake
Then insert your own $HOME/bin directory into your $PATH:
export PATH="$HOME/bin:$PATH"
Now the shell will find your version of gnatmake before the one in /usr/bin.
Try sudoing the script as yourself (sudo -u you ./script). In case you're not allow to sudo, you can also try exec VAR=val ./script. A third way would be to add another directory to $PATH with 'fake' empty scripts to shadow the ADA files.

Resources