How to Fix Node-Gyp Error on Ubuntu?

Are you trying to install the Node GYP (Generate Your Project) Add-on on Ubuntu, and have you encountered an error hindering the installation process? If that is the case, this guide is made just for you.

Node GYP (similar to “make”) takes care of the compilation process of NodeJs Add-ons, written in C or C++, without explicitly building these add-ons. However, you must have a Python environment on your Ubuntu machines to use the Node-GYP.

However, when installing Node GYP or building GYP modules on Ubuntu, users are often met with an error that stops the current process. There are a few common reasons for encountering errors with Node-GYP, and this guide will provide solutions for these reasons.

Let’s get started!

How to Fix Node-Gyp Error on Ubuntu?

To fix the Node-GYP error on Ubuntu, you must ensure that you are using the updated Ubuntu Operating System. Old packages can cause mismatch errors when building the GYP modules. After that, you must also ensure that the Python version matches the required version for the GYP Module.

In rare cases, you can have this error due to the install directories being different for the Node Project and the Node-GYP, which can cause the system not to load the GYP when building add-ons.

Let’s look at the solutions in detail.

Update Your Ubuntu System

A version mismatch can cause the GYP error if your Ubuntu packages are outdated. Therefore, you must start by updating the installed packages in your Ubuntu.To do this, open up a new terminal session on your Ubuntu machine by pressing the key combination “CTRL + ALT T,” then run the following commands inside the terminal.

sudo apt update -y && sudo apt upgrade -y

Running these commands will require you to have superuser rights. Therefore, a prompt will appear in the terminal asking for the sudo password. Type in the sudo password and press the “Enter” key to execute.

How to Fix Node-Gyp Error on Ubuntu?

These commands update the apt packages list on your Ubuntu machine and then upgrade the packages according to the new version on the apt packages list.

How to Fix Node-Gyp Error on Ubuntu?

After that, you need to install the build-essentials and the software properties command to ensure that you do not encounter any errors during the installation processes of Node-gyp or while building modules using Node-gyp. Therefore, run the following command in the terminal.

sudo apt-get install build-essential software-properties-common -y

How to Fix Node-Gyp Error on Ubuntu?

Once the update process is done, re-run your GYP task and check if the error still exists.

Re-install Node, NPM, and GYP

Suppose you use the same Ubuntu machine to work with various Node projects requiring installing multiple node modules and frameworks. In that case, the chances of encountering errors increase due to package contradictions.

In such cases, the best solution is to remove Node, NPM, and its packages and install them again from scratch. To do this, open up a new terminal session on your Ubuntu machine and then type in the following commands.

sudo apt purge --autoremove nodejs npm

Executing this command will remove NodeJS and NPM from Ubuntu’s repository, and then you will have to remove it from the source directory. Therefore, you must find the source directory for Node and NPM by running the following commands.

which node
which npm

How to Fix Node-Gyp Error on Ubuntu?

After that, you need to remove the directories that contain Node and NPM by running the following command.

sudo rm -rf /usr/bin/node /usr/bin/npm

However, if the “which” command shows you different directories, you must put your Node and NPM directories in the above command.

Once the Node and NPM have been successfully installed from your Ubuntu machine, install them again by running the following commands.

sudo apt-get update
sudo apt-get install -y nodejs
sudo apt-get install -y npm

How to Fix Node-Gyp Error on Ubuntu?

After Node and NPM have been installed on your Ubuntu machine, you can use the NPM to install Node-Gyp on your machine.

sudo npm install -g node-gyp

Lastly, try re-running the building process and see if add-ons can be successfully built without encountering any errors.

Configure Node-GYP Globally

If you have the “GYP Exit Code 1” error during the compilation process and the error log prompts you that the error is “pkg_resources.DistributionNotFound”, then Node-GYP could not be found by the node during the compilation.

How to Fix Node-Gyp Error on Ubuntu?

However, it does not depend on installing the Node GYP module but rather on the correct configuration of the GYP module. Therefore, the best solution for such an error is installing the Node-GYP module “globally” and configuring its path.

To do this, open up a terminal in your project and run the following commands.

npm install --global npm@latest
npm install --global node-gyp@latest
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js

Running these commands will update the npm to the latest version and set it as a global default; the same goes for the node-gyp. Moreover, it will configure the node-gyp in node modules.

Remove Node Modules & Dependencies

When trying to build modules with the gyp package, you are sometimes met with the “make” error with error code “2”. A solution to remove this error is to ensure build-essentials are installed on your Ubuntu machine. If they are not installed on your machine, run the following command on the terminal.

sudo apt install -y build-essential

The build essentials include the required packages that allow the “make” to work flawlessly. However, if that doesn’t fix the problem, you must head inside your project’s source directory, remove the “Node Modules” directory, and re-install the dependencies.

To do this, run the following commands within the source directory of your project.

rm -rf node_modules
rm -f package-lock.json
rm -f yarn.lock
npm cache clean --force
npm install

Afterward, try re-running the process and observe if the building process is successful without encountering the “make” error with the code “2”.

Use the “Sass” Package

If you are working with Sass packages and have installed it using the deprecated “node_sass” package, then that may be the root cause of the problem of “make an error with error code 2”. In this case, you must remove the deprecated module “node_sass” and install the newer version named “sass.”

To do this, open up the project’s root directory in the terminal and type in the following commands.

npm uninstall node-sass
npm install sass --save-dev

Once the newer package has been installed on your system, you can try re-running the make process, and it will not return an error caused by the usage of the deprecated package.

Affordable VPS Hosting With Dracula Servers

Looking for reliable and budget-friendly Virtual Private Server (VPS) hosting? Look no further than Dracula Servers. Dracula Servers offers a range of VPS hosting plans tailored to meet diverse needs. With competitive pricing, robust performance, and a user-friendly interface, it’s an excellent choice for individuals and businesses alike.

Explore the Dracula Servers website to discover hosting solutions that align with your requirements and take your online presence to new heights with their affordable and efficient VPS hosting services.

Visit Dracula Servers and experience reliable VPS hosting without breaking the bank.


A user can encounter various errors while trying to work with the Node-GYP on Ubuntu, such as errors during Node-GYP installation and while building modules with Node-GYP.

To fix this issue, start by updating your Ubuntu system and upgrading all of the outdated packages. Next, ensure that the “build-essentials” and the “software-properties-common” are installed on your Ubuntu machine to avoid any errors during Node-GYP installation.

If a contradiction between node packages causes the error and modules, you can reset Node and NPM on your Ubuntu machines. However, if the error is caused by incorrect installation of Node-GYP, then install it globally and configure the node to use the “-g” preset by default.

Lastly, if you are having the “make” error while working with the node package “node_sass,” then simply remove the “node_sass” package and use the new “sass” package. The reason for removing the “node_sass” is that it has been deprecated.

Check out More Linux Tutorials Here!

Notify of
Inline Feedbacks
View all comments
× Dracula Servers

Subscribe to DraculaHosting and get exclusive content and discounts on VPS services.