Reputation: 11
I'm trying to install npm live-server on wsl (windows subsystem for linux)
after i install nodejs and npm with:
sudo apt install nodejs npm
and try to install live-server with npm:
npm install live-server
I get this error:
/usr/bin/node: 1: Syntax error: ")" unexpected
and not only when installing live-server.. it return this error on any npm command for example:
npm -v
how can i fix it?
Upvotes: 1
Views: 4941
Reputation: 1
The same problem happened to me as you, my environment is WSL1+ubuntu2404,follow this Official ubuntu tutorial for developing on wsl with ubuntu, I installed nodejs and npm, and when I typed ‘npm install’, I was prompted with /usr/bin/node: 1: Syntax error: ’(” unexpected
; by coincidence I opened the vscode's tutorial, and after typing in the commands for installing nodejs and npm from that tutorial, it worked fine!You can try it too
sudo apt-get update
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
Upvotes: 0
Reputation: 151
Installing the pre-built binary, resolved the issue for me:
Downloading from: https://nodejs.org/en/download/prebuilt-binaries
unxz node-v22.12.0-linux-x64.tar.xz
tar -xvf node-v22.12.0-linux-x64.tar --strip-components=1 -C /usr/
credits: https://askubuntu.com/questions/1524639/usr-bin-node-cant-run-due-to-an-exec-format-error
Upvotes: 0
Reputation: 1562
I had this issue on Ubuntu (in WSL) when running npm
after having installed the latest node with nvm install node
(23.1.0).
Seems related to that particular version, I deinstalled with nvm uninstall node
, then installed latest LTS with nvm install --lts
and all is fine.
Upvotes: 3
Reputation: 11
There was a problem solved in this way
nvm install node
nvm use node
Upvotes: 1
Reputation: 36
Assuming you use ubuntu:
The version of Node.js included with Ubuntu, version 10.19, is unsupported. You should not use this version in production.
Here is a good tutorial of how to install nodejs from DigitalOcean: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04
cd ~
curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
sudo apt install nodejs
Upvotes: 1