The real solution to npm-cli.js: No such file or director when installing nodejs under linux


Install the nodejs official website under centos today, download the installation package,
decompress it
, throw it on a remote machine,
add environment variables,
and execute

>node -v
v10.14.2

normal

implement

>npm -v
*******/npm: line 1: ../lib/node_modules/npm/bin/npm-cli.js: No such file or directory

An error was reported.
Take a look, there is no such file?
Go to the corresponding directory to see, there is this file,
that is the problem of the path,
go to the bin and look at the npm file,
what is the relative path in it, change it to an absolute path
and execute

>npm -v
Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    completion, config, create, ddp, dedupe, deprecate,
    dist-tag, docs, doctor, edit, explore, get, help,
    help-search, hook, i, init, install, install-test, it, link,
    list, ln, login, logout, ls, outdated, owner, pack, ping,
    prefix, profile, prune, publish, rb, rebuild, repo, restart,
    root, run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

[email protected] /app/nodejs/lib/node_modules/npm

Why can’t I get the version number
and try another command

npm install
npm version

Why do they all return the above thing?

I searched online and found some solutions, such as executing a script or something.
I don’t think it should be. Nodejs has been developed for so long, how could it be possible that even the installation of linux is still a semi-finished product? This problem must exist in me

turn back and start over

Looking back at the downloaded node installation package, I found a problem

Use the software to open the installation package.
The npm and npx files in the bin directory are both 0 bytes
, but the one I uploaded is 38 bytes.

It turns out that the two file systems of windows and linux are different.
These two files are two linux soft links.
Windows does not have the same thing as linux soft links.
Therefore, when decompressing, these two files become internal inclusions. the text of the link address

../lib/node_modules/npm/bin/npm-cli.js

When we use this to execute, we will naturally encounter the problem of relative path

The real solution is to unzip it under linux

tar -xJvf node-v10.16.3-linux-x64.tar.xz

fix environment variables

>node -v
v10.14.2
>npm -v
6.4.1

you're done

Welcome to pay attention to the official account, communicate together and make progress together
Welcome to pay attention to the official account, communicate together and make progress together

Guess you like

Origin blog.csdn.net/cowcomic/article/details/100777525