When installing YouCompleteMe for vim, I want to install support for Java and Javascript. Following instructions from here, I therefore run:
sudo /usr/bin/python3.6 ./install.py --java-completer --ts-completer
However, it errors out with the following message:
...
[100%] Linking C shared library /home/vagrant/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/cregex/regex_3/_regex.so
[100%] Built target _regex
Downloading jdt.ls from http://download.eclipse.org/jdtls/snapshots/jdt-language-server-0.54.0-202004152304.tar.gz...
Extracting jdt.ls to /home/vagrant/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/eclipse.jdt.ls/target/repository...
Done installing jdt.ls
ERROR: Unable to find executable 'npm'. npm is required to install TSServer.
This would be understandable, except I have npm already set up on my PATH
, as shown by the following:
=> npm -v
6.13.4
=> which npm
/home/vagrant/.nvm/versions/node/v8.17.0/bin/npm
Any guesses on why YouCompleteMe with ts-completer support is failing to install?
Any guesses on why YouCompleteMe with ts-completer support is failing to install?
The install fails because you are running install.py as sudo
, and the location that nvm
installs node is not in the secure_path
. The secure_path
is in use when a script runs as sudo
.
You can see the different contents of PATH
and secure_path
like this:
$ echo 'echo $PATH' | sudo sh # secure_path
$ echo 'echo $PATH' | sh # your user PATH
You can also confirm that sudo
lacks an npm
on its path like this:
$ which npm
$ sudo which npm
What to do?
One option is to run the script without sudo like this:
/usr/bin/python3.6 ./install.py --java-completer --ts-completer
Another is to copy the nvm bin contents to one of the secure_path
locations. The /usr/local/bin
is one of those.
$ find $(which npm | xargs dirname) -type l -o -type f | sudo xargs cp -t /usr/local/bin
# test
$ sudo npm -v
$ sudo node -v
After doing that, the installer will find npm
.