Error installing node-gyp on ubuntu
Asked Answered
I

14

42
npm http 200 https://registry.npmjs.org/weak/-/weak-0.2.2.tgz
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings

> [email protected] install node_modules/weak
> node-gyp rebuild

Traceback (most recent call last):
  File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 18, in <module>
    sys.exit(gyp.script_main())
AttributeError: 'module' object has no attribute 'script_main'
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.11.0-15-generic
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"

gyp ERR! node -v v0.10.15
gyp ERR! node-gyp -v v0.12.1
gyp ERR! not ok 
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the weak package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls weak
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.11.0-15-generic
npm ERR! command "node" "/usr/bin/npm" "install" "[email protected]"
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.23
npm ERR! code ELIFECYCLE

npm ERR! not ok code 0

I don't have a direct dependency on weak or node-gyp but I guess it is required by my other dependencies (express,phantom,ejs,aws-sdk,moment). Anyone faced such an issue and was able to fix?

Improper answered 16/1, 2014 at 7:38 Comment(0)
I
24

This is what worked. You need python 2.6 during the installation.

#!/bin/bash
#On Ubuntu Saucy:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 20
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10

#you can switch between 2.6 & 2.7 using:
sudo update-alternatives --config python

#Btw I installed node using ppa:chris-lea/node.js

https://github.com/TooTallNate/node-gyp/issues/363

Improper answered 16/1, 2014 at 11:0 Comment(3)
What does exactly sudo update-alternatives --config python ? it switch from 2.6 => 2.7 => 2.6 => 2.7 ... ? and how to know which python are we currently using ?Essex
you can evaluate every command line tool to its version by using which $(readlink -f `which python`)Inspiration
You can figure out the python version in use with the command python --versionImproper
S
35

If your python version isn't the source of error, check if you have "gyp" installed. This is conflicting with the gyp version in node-gyp.

apt-get remove gyp

https://github.com/TooTallNate/node-gyp/issues/363#issuecomment-32234646

Salesclerk answered 13/5, 2014 at 7:34 Comment(3)
Should be an accepted answer. Downgrading to 2.6 and using PPA is the last resort.Gammadion
I'm having this error when running npm install. the gip package is a dependency of npm, so removing it doesn not solve the issue for me as it removes npm as well... I'm on Ubuntu 14.04.Topminnow
For those with similar problems, this resolves the following error for me on Ubuntu. "error: no such option: --no-parallel"Offspring
A
35

This command sudo apt-get install build-essential helped in my case.

Afc answered 5/9, 2014 at 10:23 Comment(4)
in ubuntu 18.04 there are no build-essentials but in earlier editions of ubuntu did not have this problem thanks for your supportRebekah
The command on Linux Mint 20.3 works fine!Ingulf
This answer worked for me on ubuntu 20Julie
the answer does not work on Ubuntu 22.04Grig
I
24

This is what worked. You need python 2.6 during the installation.

#!/bin/bash
#On Ubuntu Saucy:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 20
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10

#you can switch between 2.6 & 2.7 using:
sudo update-alternatives --config python

#Btw I installed node using ppa:chris-lea/node.js

https://github.com/TooTallNate/node-gyp/issues/363

Improper answered 16/1, 2014 at 11:0 Comment(3)
What does exactly sudo update-alternatives --config python ? it switch from 2.6 => 2.7 => 2.6 => 2.7 ... ? and how to know which python are we currently using ?Essex
you can evaluate every command line tool to its version by using which $(readlink -f `which python`)Inspiration
You can figure out the python version in use with the command python --versionImproper
C
21

FWIW, I had a similar problem trying to install Protractor on Ubuntu 14.04 (DigitalOcean). Reinstalling node-gyp fixed the it:

apt-get install node-gyp
Catherin answered 7/11, 2015 at 15:44 Comment(1)
worked for me on ubuntu 22, node 18Aiaia
H
11

on Ubuntu 18, I had to install required build libs to get it working

sudo apt-get install build-essential

Update: April 2024. On Fresh Ubuntu you had to run

sudo apt update

Then

sudo apt-get install build-essential
Hijoung answered 14/11, 2018 at 13:3 Comment(1)
On a fresh Ubuntu 20 installation I had to run sudo apt update before installing build-essential.Penley
G
7

Here are the steps to install node-gyp successfully on a Ubuntu system:

1.First of all, install the "make" build tool in Ubuntu with the following commands:

sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y;

2. Then you need to install the a proper C/C++ compiler toolchain. We will be installing GCC here with the following commands:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-snapshot -y && \
sudo apt-get update && \
sudo apt-get install gcc-6 g++-6 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave 
/usr/bin/g++ g++ /usr/bin/g++-6 && \
sudo apt-get install gcc-4.8 g++-4.8 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave 
/usr/bin/g++ g++ /usr/bin/g++-4.8;

3. Install python 2.7 version. (Note: Python 3 is not supported by node-gyp).

sudo apt update
sudo apt upgrade
sudo apt install python2.7 python-pip

4. And finally install, node-gyp npm package:

npm install -g node-gyp

Additional but not important: If you have any atom keyboard-layout related issue with node-gyp then install the following one more package:

sudo apt-get install libxkbfile-dev

Thats all! It should be working fine now.

Gpo answered 3/8, 2018 at 7:22 Comment(0)
D
4

I faced this issue on Ubuntu 16.04 while trying to install the wikimedia extension mathoid.

I tried everything that was suggested and nothing worked until I did:

sudo apt-get install librsvg2-2 librsvg2-dev
Dubbin answered 31/5, 2016 at 6:11 Comment(0)
B
2

On Ubuntu 10.04, Installing libicu solved my problem.

sudo apt-get install libicu-dev

Blotch answered 27/12, 2014 at 8:20 Comment(0)
O
1

On Fedora 20, reinstalling gyp fixed this for me.

sudo yum reinstall gyp
Orpheus answered 11/3, 2015 at 19:37 Comment(0)
S
1

I already had build-essential installed. I just had to run:

sudo apt install python
Sibel answered 7/8, 2017 at 16:39 Comment(0)
A
0

In my-case it was failing on Linux-mint 19.2, for some reasons on run-time gcc++ was not accessible. So by installing the build-essentials error was resolved. PS:

build-essential package is a reference for all the packages needed to compile a Debian packages. It generally includes the GCC/g++ compilers and libraries and some other utilities. Informational for list of build-essential packages can be found on build-essentials

Arun answered 18/2, 2020 at 15:6 Comment(0)
S
0

If the error is due to " fatal error: dns_sd.h: No such file or directory 32 | #include <dns_sd.h> ", solve it by

" sudo apt-get install libavahi-compat-libdnssd-dev " , else if it is due to python2 follow @Manish Jangir method

Semela answered 21/10, 2020 at 23:49 Comment(0)
C
0

Fedora Silverblue

rpm-ostree install make automake gcc gcc-c++
Chasidychasing answered 16/7, 2022 at 18:12 Comment(0)
C
-1

What you need is just to:

sudo apt-get update
sudo apt-get upgrade

You should install nvm and a new Node version.

Clerk answered 23/4 at 10:18 Comment(3)
Can you provide more details (complete set of commands) and make sure to format your answer properly?Strega
This is not a possible solution to the error messages listed in this question. If you resolved a different error message using an update/upgrade, then you should post that as a separate question/answer pair instead. Thanks!Hobble
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewAlbarran

© 2022 - 2024 — McMap. All rights reserved.