bqui56
bqui56

Reputation: 2121

Why isn't this file being copied to my $PATH?

I was trying to add the mvim shell script to /usr/local/bin form bash as per this question and everything seemed to work; however, I am still getting "command not found" whenever I try to execute the script.

From the directory where my mvim file is (Downloads), I typed:

sudo cp -v mvim /usr/local/bin

and I get output:

mvim -> /usr/local/bin

and then it doesn't work whether I type mvim or mvim -v

I've never added something to my $PATH before, but even after looking up a number of tutorials on how it is done, I can't seem to get mvim to work as a terminal command.

EDIT:

echo $PATH

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

and

ls -l mvim

-rwxr-xr-x ...

and

ls -l /usr/local/bin

-rwxr-xr-x ...

Upvotes: -1

Views: 1375

Answers (4)

paulsm4
paulsm4

Reputation: 121809

This is what you posted:

mvim -> /usr/local/bin

I believe that's wrong. It looks like "mvim" is a symbolic link that points to the directory /usr/local/bin.

If so, this is not what you want!

Please do the following:

  1. Open a terminal (command-line) window.

  2. "cd" to the directory with your original "mvim" (the one you tried to copy to /usr/localbin)

  3. Cut/paste:

    a) the directory name

    b) ls -l mvim

    c) echo $PATH

The "echo $PATH" is also important.

Upvotes: -1

Rodrigue
Rodrigue

Reputation: 3687

Does /usr/local/bin exists?

If you run sudo cp -v mvim /usr/local/bin and the /usr/local/bin folder does not exist, cp will copy mvim to the /usr/local/ folder and name it bin.

You need to first create the folder with sudo mkdir -p /usr/local/bin. Then, you can copy mvim with the previous cp command.

Is mvim executable?

Have you made sure that /usr/local/bin/mvim has the executable flag set? Try ls -l /usr/local/bin/mvim and if the result starts with -rw-r--r--, then mvim is not executable.

You then need to run sudo chmod +x /usr/local/bin/mvim. If you now run the previous ls command again, the result should start with -rwxr-xr-x. The x means that the file is now executable by its owner, members of its group, and all other users too.

Is /usr/local/bin in your PATH?

Have you made sure that /usr/local/bin is part of your PATH variable?

Try echo $PATH and if the output does not contain /usr/local/bin, then the shell will not look for commands there. You then need to run export PATH=$PATH:/usr/local/bin

Upvotes: 7

Mat
Mat

Reputation: 206861

Either start a new shell, or type:

hash -r

so that the shell re-inspects the directories in the $PATH. (It caches the contents for efficiency, you need to reload that cache when you add things to directories in your path.)

Upvotes: 1

Igor Chubin
Igor Chubin

Reputation: 64613

Check:

  1. If /usr/local/bin/mvim is executable (add exec bit if not: chmod +x /usr/local/bin/mvim)
  2. If /usr/local/bin is in $PATH (echo $PATH)

Upvotes: 1

Related Questions