简体   繁体   English

无法使用 nvm 或 apt get install (wsl2 ubuntu) 安装 node/npm

[英]can't install node/npm with either nvm or apt get install (wsl2 ubuntu)

I can't install node/npm with either nvm or apt get install (wsl2 ubuntu).我无法使用 nvm 或 apt get install (wsl2 ubuntu) 安装 node/npm。 Here is what I tried first这是我首先尝试的

$ code export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist 
$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

It installed nvm but when I did nvm ls I only got this (no versions listed)它安装了 nvm 但是当我安装nvm ls时我只得到了这个(没有列出版本)

->       system
iojs -> N/A (default)
node -> stable (-> N/A) (default)
unstable -> N/A (default)

So I did ~/.nvm and tried apt-get install -y nodejs which seemed to work ...所以我做了~/.nvm并尝试了apt-get install -y nodejs这似乎工作......

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  npm
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 0 B/122 kB of archives.
After this operation, 932 kB of additional disk space will be used.
Selecting previously unselected package nodejs.
(Reading database ... 40014 files and directories currently installed.)
Preparing to unpack .../nodejs_12.22.9~dfsg-1ubuntu3_amd64.deb ...
Unpacking nodejs (12.22.9~dfsg-1ubuntu3) ...
Setting up nodejs (12.22.9~dfsg-1ubuntu3) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning candidates...
Scanning processor microcode...
Scanning linux images...

Failed to retrieve available kernel versions.

Failed to check for processor microcode upgrades.

No services need to be restarted.

No containers need to be restarted.

User sessions running outdated binaries:
 root @ /dev/pts/0: bash[9754,9845], sh[10875]
 root @ /dev/tty1: init[9752], wsltermd[9753]
 root @ /dev/tty2: bash[25], init[24]

No VM guests are running outdated hypervisor (qemu) binaries on this host.

Then I did node -v ...然后我做了node -v ...

bash: /usr/bin/node: cannot execute binary file: Exec format error

I am running on a brand new windows machine with win10 home.我正在一台带有win10 home的全新Windows机器上运行。 I installed wsl2/ubuntu-22.04 and have been using it with no problem.我安装了 wsl2/ubuntu-22.04 并且一直在使用它没有问题。 So everything is fresh.所以一切都是新鲜的。 I am not behind any proxy.我不支持任何代理。

I am pulling my hair out.我正在拔头发。 Can someone help me?有人能帮我吗?

EDIT: I did apt install nodejs npm from a vscode wsl terminal and got a very long install which seemed successful.编辑:我确实从 vscode wsl 终端apt install nodejs npm ,并且安装了很长的时间,看起来很成功。 Now when I run npm i -g vite I get ...现在当我运行npm i -g vite我得到...

/usr/bin/node: 1: ELF: not found
/usr/bin/node: 2: : not found
/usr/bin/node: 4: Syntax error: Unterminated quoted string

so I'm losing even more hair.所以我失去了更多的头发。 By the way, I've been following The IT Crowd advice and rebooting often.顺便说一句,我一直在遵循 IT Crowd 的建议并经常重启。

I got node/npm installed by reverting to ubuntu 18.04, installing nvm, and doing nvm install 'lts/*' .我通过恢复到 ubuntu 18.04、安装 nvm 并执行nvm install 'lts/*'安装了 node/npm。
nvm ls still doesn't give any results so I'm surprised the install worked. nvm ls仍然没有给出任何结果,所以我很惊讶安装成功了。 It's also a pain that I can't list the node versions.无法列出节点版本也是一种痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM