centos 安装完 node, /usr/local/bin 下有 node 却无法执行?

2020-08-10 23:02:56 +08:00
 selfcreditgiving

安装方式是通过下载编译好的 node 二进制文件来安装。

安装:

cd ~

wget https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz

sudo tar --strip-components 1 -xvJf node-v* -C /usr/local

检查环境变量 /usr/local/bin 是有的:

/usr/local/bin/node --version 可以执行,node --version 却不可以。


# ls /usr/local/bin
node  npm  npx

# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

# /usr/local/bin/node --version
v12.18.3

# node --version
-bash: /usr/bin/node: No such file or directory

3468 次点击
所在节点    问与答
22 条回复
whenov
2020-08-10 23:04:07 +08:00
# which node
swulling
2020-08-10 23:05:56 +08:00
这是因为 /usr/bin/node 是一个丢失了引用的软连接,把这个删了就行
selfcreditgiving
2020-08-10 23:15:53 +08:00
@swulling #2 好像这个都不是 软连接,是一个实际的执行文件?

# ls -al /usr/local/bin
total 47516
drwxr-xr-x. 2 1001 1001 4096 Aug 10 23:13 .
drwxr-xr-x. 13 root root 4096 Aug 10 22:48 ..
-rwxr-xr-x 1 1001 1001 48646656 Jul 22 23:00 node
lrwxrwxrwx 1 1001 1001 38 Jul 22 23:00 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 1001 1001 38 Jul 22 23:00 npx -> ../lib/node_modules/npm/bin/npx-cli.js
vuuv
2020-08-10 23:27:46 +08:00
先确认 `/usr/bin/node`是否存在。如果存在,那么检查文件类型是否正确,包括 ELF 是 32 位还是 64 位。
如果文件不存在,那么 `hash -r`命令清空 bash 的命令路径缓存。也可以直接开始清空,毕竟 path 里 /usr/local/bin 目录比 /usr/bin 优先。
swulling
2020-08-10 23:58:25 +08:00
@selfcreditgiving 那就是他引用的动态链接库不存在
jtnwm
2020-08-10 23:59:16 +08:00
也许缺失依赖? ldd /usr/bin/node 看看是不是缺了啥
swulling
2020-08-11 00:01:09 +08:00
这种自行安装的方式真的很不好,不适合初级用户,瞎装一通只是一两句也没法修。

简单点选一个源从源里装最合适
selfcreditgiving
2020-08-11 00:04:48 +08:00
@swulling #7 主要是 那个什么 update 源没更新, 我一装是 node v4.2 ? 太老了 ,我又卸载了。 但是 那个 yum update 我是有阴影了, 执行一次要等很久。 而且我担心会影响到现有环境。
selfcreditgiving
2020-08-11 00:06:27 +08:00
@jtnwm #6 帮忙看看了 多谢
# ldd /usr/local/bin/node
linux-vdso.so.1 => (0x00007ffeb23d4000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f93c65ac000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f93c62a5000)
libm.so.6 => /lib64/libm.so.6 (0x00007f93c5fa2000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f93c5d8c000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f93c5b70000)
libc.so.6 => /lib64/libc.so.6 (0x00007f93c57a2000)
/lib64/ld-linux-x86-64.so.2 (0x0000561e91325000)
leo108
2020-08-11 00:11:09 +08:00
1 、2 、4 、6 楼的兄弟都在说 /usr/bin/node,楼主一个劲地操作 /usr/local/bin/node,能找出问题才怪。特别是 1 楼的命令有 90% 的概率能找到问题,不知道为什么楼主选择性忽略。
calmzhu
2020-08-11 00:17:17 +08:00
这是没找到,跟动态链接库没关系。

ls -la `which node`
看一下,如果不是指向 /usr/local/bin/node 直接删掉。

如果是,关掉 shell 重新开一下。
selfcreditgiving
2020-08-11 00:29:02 +08:00
@leo108 #10 我想可能是打错了, /usr/bin/node 是没有的

# ls -al /usr/bin/node
ls: cannot access /usr/bin/node: No such file or directory


@calmzhu #11 是指向这个 /usr/local/bin/node

# ls -la `which node`
-rwxr-xr-x 1 1001 1001 48646656 Jul 22 23:00 /usr/local/bin/node

重启 shell 指的是重启 笔记本上的 终端吗, 还是服务器上面的 shell,笔记本我已经重启过了的。服务器的东西我尽量不想动, 这个上面还跑着好几个 应用的 docker 容器呢
vuuv
2020-08-11 00:32:02 +08:00
@selfcreditgiving 那么看下 #4 我的回复,谢谢。
calmzhu
2020-08-11 00:37:09 +08:00
不用重启服务器。重启过的话。那么文件位置对的。

看下这个文件类型。
file /usr/local/bin/node
看一下文件类型是 elf 还是 ascii text

如果是 ASCII text,用文本打开看看第一行的内容。
selfcreditgiving
2020-08-11 00:48:49 +08:00
@vuuv #13
@calmzhu #14

# file /usr/local/bin/node
/usr/local/bin/node: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=48b59ee612c13e556e0b1fae84c06398f4fc942a, not stripped

好像是 64 的,elf
calmzhu
2020-08-11 00:50:50 +08:00
@calmzhu
不用看了。之前是怀疑 node 用脚本管理。然后里面第一行指向了#!/usr/bin/node

但是看你 ls -la 出来的大小应该是二进制。


用 strace 跟一下调用看看

strace node --version
selfcreditgiving
2020-08-11 01:07:16 +08:00
@calmzhu #16

我试一下,node --version 又可以了,,, 记起来 我重启 mac pro 后, 没有试过 node --version 能不能用

重启的原因其实主要是上网很慢,各种操作都卡 ssh 远程连接 阿里云服务器,wget 下载文件 node 安装包 也很慢。

而且我在 终端里输入命令 特别的卡, 所以重启了一下, 重启后网速快多了, 而且输入也不卡顿。

但是我奇怪的是, 我连接 阿里云服务器下载, 那个下载是 阿里云服务器去下载, 和我 mac pro 的网速有什么关系呢?

我记得昨天 mac pro 开了很多 软件没关( IDEA 、Chrome 、Evernote 那些),就合上盖休眠了, 可能是这个原因
selfcreditgiving
2020-08-11 01:08:53 +08:00
@calmzhu #16 顺便附上 命令结果, 不过应该没关系了

# strace node --version
execve("/usr/local/bin/node", ["node", "--version"], [/* 22 vars */]) = 0
brk(NULL) = 0x4aee000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5ce4a71000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=28662, ...}) = 0
mmap(NULL, 28662, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f5ce4a6a000
close(3) = 0
open("/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\r\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=19288, ...}) = 0
mmap(NULL, 2109712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f5ce464d000
mprotect(0x7f5ce464f000, 2097152, PROT_NONE) = 0
mmap(0x7f5ce484f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f5ce484f000
close(3) = 0
open("/lib64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \262\5\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=991616, ...}) = 0
mmap(NULL, 3171168, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f5ce4346000
mprotect(0x7f5ce442f000, 2093056, PROT_NONE) = 0
mmap(0x7f5ce462e000, 40960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe8000) = 0x7f5ce462e000
mmap(0x7f5ce4638000, 82784, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f5ce4638000
close(3) = 0
open("/lib64/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20S\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1137016, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5ce4a69000
mmap(NULL, 3150120, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f5ce4044000
mprotect(0x7f5ce4145000, 2093056, PROT_NONE) = 0
mmap(0x7f5ce4344000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x100000) = 0x7f5ce4344000
close(3) = 0
open("/lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220*\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=88776, ...}) = 0
mmap(NULL, 2184192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f5ce3e2e000
mprotect(0x7f5ce3e43000, 2093056, PROT_NONE) = 0
mmap(0x7f5ce4042000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x7f5ce4042000
close(3) = 0
open("/lib64/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260l\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=141968, ...}) = 0
mmap(NULL, 2208904, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f5ce3c12000
mprotect(0x7f5ce3c29000, 2093056, PROT_NONE) = 0
mmap(0x7f5ce3e28000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16000) = 0x7f5ce3e28000
mmap(0x7f5ce3e2a000, 13448, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f5ce3e2a000
close(3) = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340$\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2151672, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5ce4a68000
mmap(NULL, 3981792, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f5ce3845000
mprotect(0x7f5ce3a07000, 2097152, PROT_NONE) = 0
mmap(0x7f5ce3c07000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c2000) = 0x7f5ce3c07000
mmap(0x7f5ce3c0d000, 16864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f5ce3c0d000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5ce4a67000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5ce4a65000
arch_prctl(ARCH_SET_FS, 0x7f5ce4a65780) = 0
selfcreditgiving
2020-08-11 01:09:45 +08:00
一次贴不了太长,分两次:

mprotect(0x7f5ce3c07000, 16384, PROT_READ) = 0
mprotect(0x7f5ce3e28000, 4096, PROT_READ) = 0
mprotect(0x7f5ce4042000, 4096, PROT_READ) = 0
mprotect(0x7f5ce4344000, 4096, PROT_READ) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5ce4a64000
mprotect(0x7f5ce462e000, 32768, PROT_READ) = 0
mprotect(0x7f5ce484f000, 4096, PROT_READ) = 0
stat("/etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned", 0x7fff97bd7750) = -1 ENOENT (No such file or directory)
mprotect(0x2c7e000, 12288, PROT_READ) = 0
mprotect(0x7f5ce4a72000, 4096, PROT_READ) = 0
munmap(0x7f5ce4a6a000, 28662) = 0
set_tid_address(0x7f5ce4a65a50) = 6852
set_robust_list(0x7f5ce4a65a60, 24) = 0
rt_sigaction(SIGRTMIN, {0x7f5ce3c18790, [], SA_RESTORER|SA_SIGINFO, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7f5ce3c18820, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
futex(0x7f5ce464a8ac, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7f5ce464a8b8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
brk(NULL) = 0x4aee000
brk(0x4b0f000) = 0x4b0f000
brk(NULL) = 0x4b0f000
futex(0x2c9ae50, FUTEX_WAKE_PRIVATE, 2147483647) = 0
getuid() = 0
geteuid() = 0
getgid() = 0
getegid() = 0
rt_sigprocmask(SIG_SETMASK, [USR1], NULL, 8) = 0
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
rt_sigaction(SIGHUP, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGILL, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGTRAP, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGABRT, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGBUS, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGFPE, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGUSR1, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGSEGV, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGUSR2, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGPIPE, {SIG_IGN, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGALRM, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGSTKFLT, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGCONT, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGTSTP, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGTTIN, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGTTOU, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGURG, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGXCPU, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGXFSZ, {SIG_IGN, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGVTALRM, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGPROF, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGWINCH, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGIO, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGPWR, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGSYS, {SIG_DFL, [], SA_RESTORER, 0x7f5ce3c215d0}, NULL, 8) = 0
fcntl(0, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE)
ioctl(0, TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B9600 opost isig icanon echo ...}) = 0
fcntl(1, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE)
ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0
fcntl(2, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE)
ioctl(2, TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(2, TCGETS, {B9600 opost isig icanon echo ...}) = 0
rt_sigaction(SIGINT, {0x9d6080, ~[RTMIN RT_1], SA_RESTORER|SA_RESETHAND, 0x7f5ce3c215d0}, NULL, 8) = 0
rt_sigaction(SIGTERM, {0x9d6080, ~[RTMIN RT_1], SA_RESTORER|SA_RESETHAND, 0x7f5ce3c215d0}, NULL, 8) = 0
getrlimit(RLIMIT_NOFILE, {rlim_cur=65535, rlim_max=65535}) = 0
ioctl(0, FIOCLEX) = 0
ioctl(1, FIOCLEX) = 0
ioctl(2, FIOCLEX) = 0
ioctl(3, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(4, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(5, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(6, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(7, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(8, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(9, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(10, FIOCLEX) = -1 EBADF (Bad file descriptor)
ioctl(11, FIOCLEX) = -1 EBADF (Bad fi
calmzhu
2020-08-11 01:15:39 +08:00
嗯。那应该是重启后恢复的。bash 的 path 缓存导致的。。网速那个,阿里云的下载是本身就很慢吧﹉我的阿理云访问这种国外的经常十几 kb

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/697208

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX