How to Fix “Error While Installing NodeJS” on Ubuntu?

Are you trying to install NodeJs on your Ubuntu machine but constantly encountering errors? If that is the case, this guide is just for you!

NodeJS, the runtime server environment for JavaScript, has complete support for all operating systems, including Windows, macOS, and Linux (Ubuntu included). It can be installed on any Ubuntu machine using its default “apt” package manager and default apt repository.

However, users have encountered various errors while installing NodeJs on their Ubuntu-based operating systems. These errors range from DPKG being broken, consumed, or NodeJs being incorrectly installed constantly. This guide will explain all of the errors that can occur during the installation of NodeJS on your Ubuntu machine and provide their solutions in detail.

Let’s get started with the answer!

How to Fix “Error While Installing NodeJS” on Ubuntu?

Use the correct “apt” command to install NodeJS on your Ubuntu machine with the sudo privileges. Otherwise, if you are having a DPKG lock error while trying to install NodeJS from the apt repository, then use the kill command to kill the process that is using the DPKG.

Other than this, users often install NodeJS correctly on their system, but try to access it using the wrong command, which shows them the “NodeJS not found” error. Therefore, use the correct command to access the terminal of “node” on your system.

Let’s go over these errors and their solutions in detail!

Use APT to Install NodeJS

If you are new to Ubuntu or any Linux-based operating system and are trying to install NodeJS on your system, then it is highly likely that you are using the wrong command while trying to install NodeJS.

The first thing you want to do is to ensure that there is no previous installation of NodeJS on your Ubuntu system, which you can do by opening a new terminal  (CTRL + ALT + T) and executing the following commands inside it.

node
nodejs

How to Fix “Error While Installing NodeJS” on Ubuntu?

As you can see from the output image above, the commands “node” and “nodejs” were not found, meaning there is no previous installation.

Therefore, the next thing that you want to do is to update the apt packages list by running the following command inside the terminal.

sudo apt update

However, executing the above command will require you to have sudo or root user privileges, and you will be prompted to provide the sudo password to execute the command.

How to Fix “Error While Installing NodeJS” on Ubuntu?

Therefore, type in the password for the sudo user and press the “Enter” key to continue. Once the apt packages have been updated, you can install NodeJS using the “Apt” package manager by running the following command.

sudo apt-get install nodejs

As you can see, the name of the Node package inside the Ubuntu repository is “nodejs.” Once you execute the command, you will be prompted with a confirmation for installing NodeJS on your system.

How to Fix “Error While Installing NodeJS” on Ubuntu?

Type “Y” into the terminal and press “Enter” to continue the installation process. Once the installation is done, you can verify it by opening the Node Shell. To do this, simply type the following command inside the terminal.

nodejs

Once you execute the command, you will see the following output on the terminal that will ensure that the NodeJS has been successfully installed on your system.

How to Fix “Error While Installing NodeJS” on Ubuntu?

Use the Correct Command to Access NodeJS

A common issue with users new to Ubuntu or Linux is using the wrong command to access the Node shell even after a successful installation. Even though the keywords “node” and “nodejs” refer to the same package, they can still have different meanings in Ubuntu.

This is an alias issue if you are trying to access the node shell using the command “node” or “nodejs” after successfully installing it. The package name is “node js” in Ubuntu, but it can also be accessed by simply typing the keyword “node” as it is stored as an alias inside the “env” file.

If anything were to happen to this env configuration, then there is a high chance that the aliases won’t work. Therefore, try using the alternative keyword to see which one works.

How to Fix “Error While Installing NodeJS” on Ubuntu?

Suppose you are unsure whether the issue is incorrect installation or command usage. In that case, you can verify the existence of NodeJS on your Ubuntu machine by running the following commands.

which node
which nodejs

When you execute the above commands, the terminal will display the path of each individual command. This can also help you determine whether the alias is working or not.

How to Fix “Error While Installing NodeJS” on Ubuntu?

Fix Busy DPKG Lock Error During Installation

If you are trying to install any package inside your Ubuntu machine and are met with the error statement “Could not get lock xx/xx/dpkg,” a busy Dpkg causes the issue. If any software updates or other installations are running, then the Dpkg gets busy in that process. If you try installing NodeJS with a Busy Dpkg, you get the following error.

How to Fix “Error While Installing NodeJS” on Ubuntu?

There are a few ways to fix this, including waiting for updates or installations to complete (if any). However, if waiting is not your thing, the second method is to kill the process, keeping the dpkg busy.

To do this, observe the error statement as it mentions the PID (process ID) of the process holding the DPKG, for example.

How to Fix “Error While Installing NodeJS” on Ubuntu?

After that, use the following command template to kill the respective process using its PID.

sudo kill -i9 <process_ID>

To follow up with the example showcased in the image above, the kill command will be as follows.

sudo kill -9 6793

After this, type in the password for the root user (if prompted) and press the “Enter” key to execute the kill command. Once you have done that, re-execute the installation command for the NodeJS, and the installation will work perfectly.

How to Fix “Error While Installing NodeJS” on Ubuntu?

Fix the SubProcess Error Code 1 During NodeJS Installation

If you are trying to install NodeJS on your Ubuntu machine but are constantly met with the error statement “Dpkg: subprocess was killed by signal (broken pipe)” or the statement that the subprocess exited with the error code 1, then you need to purge your system of any previous installation of NodeJS and re-install node from the start.

The error of subprocess exited with error code 1 occurs when you are trying to install different versions of NodeJS in the same Ubuntu system. When you try to install NodeJS with its Debian file while having a version installed through apt, things get a little messy.

How to Fix “Error While Installing NodeJS” on Ubuntu?

You would use the Debian file to install a specific version of NodeJS for many reasons, but you will encounter this error when you unpack the Debian file.

To manage this error, you need to either use the NPM package manager to deal with different versions of NodeJS or completely remove the previous installations and install your preferred version through its Debian file.

To do this, open up a new terminal session and remove the new source’s link by running the following commands.

cd /etc/apt/sources.list.d
sudo rm nodesource.list

Once that is done, update your apt packages list and fix any broken packages by running the following commands in the terminal.

sudo apt --fix-broken install
sudo apt update

How to Fix “Error While Installing NodeJS” on Ubuntu?

After updating the apt packages list, remove the current version of NodeJS and NodeJS-doc by running the following command.

sudo apt remove nodejs && sudo apt remove nodejs-doc

How to Fix “Error While Installing NodeJS” on Ubuntu?

Type “Y” and press the “Enter” key to confirm the uninstallation process and wait for it to complete fully. After that, remove any left-over files or symbolic links by running the following command.

sudo apt-get autoremove

How to Fix “Error While Installing NodeJS” on Ubuntu?

Once that is done, you can install the NodeJS version of your choice using its Debian file without any error.

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.

Create Symbolic Link – Post Installation

As mentioned earlier, the “node” and the “nodejs” are separate commands with different meanings. If you are trying to access the NodeJS shell by using the command “node” or trying to run a node project with the keyword “node” and are met with the error “command not found,” then you can simply use the keyword “node js” instead of “node.”

However, another solution for this issue is to create a symbolic link so that you can use the “node” keyword to access NodeJS.  To do this, open up a new terminal session and execute the following command.

sudo ln -s /usr/bin/nodejs /usr/bin/node

Once done, you can verify it by accessing the NodeJS shell using the command “node” inside the terminal, giving you the following output.

How to Fix “Error While Installing NodeJS” on Ubuntu?

Conclusion

Installing NodeJS on a Ubuntu machine is a straightforward task. However, it can still come across various errors. If you cannot install NodeJS on your Ubuntu machine, then ensure that you are using the correct package name for Node in the “apt install” command, as it is common for new users to assume that the package is called “node” instead of “NodeJS.”

If you have successfully installed NodeJS on your Ubuntu machine but are unable to access it using the keyword “node,” then you can either use the keyword “node js” or simply create a symbolic link that will allow you to use the keyword “node.” If you are getting the error that the dpkg is busy, find the process ID of the process holding the dpkg and kill it using the “kill” command.

Lastly, if you are trying to install a different version of node using its Debian package while having a version installed through apt, then first remove the previous version from your system.

Check out More Linux Tutorials Here!

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
× Dracula Servers

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