最近想更新node版本到v20,根据官方文档(GitHub - nodesource/distributions: NodeSource Node.js Binary Distributions)更新:
Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ apt-get install -y nodejs
在执行上述语句后,报如下错误:
## Installing the NodeSource Node.js 20.x repo...
## Populating apt-get cache...
+ apt-get update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
Error executing command, exiting
后来想了想,嗯,我当前这个用户虽然权限很高,但不是root,可能还是权限不够,查看了下文件权限,果然只能是root。
$ ls -al /var/lib/apt/lists/lock
-rw-r----- 1 root root 0 Aug 11 22:06 /var/lib/apt/lists/lock
其实人家nodejs安装上写了as root,还是有点侥幸了。
老老实实把sudo加上再执行就没问题了。
$ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - && sudo apt-get install -y nodejs