Как полностью удалить node js и npm
Перейти к содержимому

Как полностью удалить node js и npm

  • автор:

Как полностью удалить node js и npm

npm uninstall

Scoped package

npm uninstall <@scope/package_name>

Example

npm uninstall lodash

Удаление локального пакета без его удаления из package.json

Example

npm uninstall —no-save lodash

  • Система Unix (например, OSX): ls node_modules
  • Системы Windows: dir node_modules

Unscoped package

npm uninstall -g

Scoped package

npm uninstall -g <@scope/package_name>

Example

npm uninstall -g jshint

How to Install/Uninstall NodeJS on Ubuntu 18.04

How to Install/Uninstall NodeJS on Ubuntu 18.04

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

NodeJS is a JavaScript framework that allows you to build fast network applications with ease. In this guide, we delve in and see how you can How to install NodeJS on Ubuntu 18.04.

Step 1: Adding the NodeJS PPA to Ubuntu 18.04

To start off, add the NodeJS PPA to your system using the following commands.

sudo apt-get install software-properties-common 

Sudo Apt Install Software Properties Common

Sample Output Next, add the NodeJS PPA.

curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash - 

Add Current NodeJS Release

Sample Output Great! In our next step, we are going to run the command for installing NodeJS.

Step 2: Install NodeJS on Ubuntu

After successfully adding the NodeJS PPA, It’s time now to install NodeJS using the command below.

sudo apt-get install nodejs 

Install NodeJs on Ubuntu 18.04

Sample Output This command not only installs NodeJS but also NPM (NodeJS Package Manager) and other dependencies as well.

Step 3: Verfiying the version of NodeJS and NPM

After successful installation of NodeJS, you can test the version of NodeJS using the simple command below.

node -v 

testing the version of NodeJS in Ubuntu 18.04

Sample Output For NPM, run

npm -v 

Testing the version of NPM

Sample Output

Step 4: Creating a Web Server demonstration

This is an optional step that you can use to test if NodeJS is working as intended. We are going to create a web server that displays the text “Congratulations! node.JS has successfully been installed !” Let’s create a NodeJS file and call it nodeapp.js

vim nodeapp.js 

Add the following content

var http = require('http'); http.createServer(function (req, res) < res.writeHead(200, ); res.end('Congratulations! node.JS has successfully been installed !\n'); >).listen(3000, " server-ip); console.log('Server running at https://server-ip:3000/'); 

Save and exit the text editor Start the application using the command below

node nodeapp.js 

Running Node Js Application

Sample Output This will display the content of the application on port 3000. Ensure the port is allowed on the firewall of your system.

ufw allow 3000/tcp ufw reload 

Now open your browser and browse the server’s address as shown

https://server-ip:3000 

Success Nodejs Has Successfully Been Instaled

Uninstall NodeJS from Ubuntu

If you wish to uninstall NodeJS from your Ubuntu system, run the command below.

sudo apt-get remove nodejs 

The command will remove the package but retain the configuration files. To remove both the package and the configuration files run:

sudo apt-get purge nodejs 

As a final step, you can run the command below to remove any unused files and free up the disk space

sudo apt-get autoremove 

Great! We have successfully installed and tested the installation of NodeJS. We also learned how to uninstall NodeJS from Ubuntu and clean up space.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases. Learn more about us

How to uninstall Node.js? Remove Node.js from your system completely

How to uninstall Node.js? Remove Node.js from your system completely

There is no restriction on the type of programming language used for writing server-side code. Some of the popular examples include PHP, Ruby, C#, Python, and Javascript. Out of all these, Javascript is very much popular because of its beginner-friendliness and being able to be used both on the client-side and server-side as well.

As the server-side runtime environment for Javascript, Node.js lets you build scalable web applications with ease. Despite its popularity among beginning developers, Node.js does not fit every developer’s needs, especially those with different language backgrounds or preferences.

This tutorial will walk you through a step-by-step guide to completely remove Node.js from your computer. Let’s take a deep breath and dive right in!

Prerequisites

Before uninstalling Node.js, it is important that we check if Node.js is properly installed in our system or not. The way we can check that varies by the operating system.

Check if Node.js installed on Windows

  • Using File Explorer:
  • Go to File Explorer, open This PC ->C:/ drive.
  • Look for the Nodejs folder in the directory where you installed Nodejs originally.
  • Some of the other files where we can check for Nodejs or npm files:
    • C:Program Files (x86)Nodejs
    • C:Program FilesNodejs
    • C:Users»user»AppDataRoamingnpm
    • C:Users»user»AppDataRoamingnpm-cache

    Using CMD:

    • Search for “ cmd ” in the start menu. Right-click on it and select “Run as administrator”.
    • Or, Press Win+R to open “run”. Enter “ cmd ” and hit Ctrl+Shift+Enter to open the command prompt as administrator.
    • Write the following command:
    node --version
    Code language: JavaScript (javascript)

    If you get a result like this, it indicates Node is correctly installed on your system:

    v16.16.0
    Code language: JavaScript (javascript)

    Check if Node.js installed on Linux

    You can check if Node.js is installed by typing node -v in Terminal. The version number will appear in the terminal. It should look something like this:

    v16.16.0
    Code language: JavaScript (javascript)

    Check if Node.js installed on Mac

    1. Press command+space to open Spotlight Search.
    2. Type “ Terminal ” and press enter.
    3. Check if Node.js is installed by typing node -v in Terminal.
    4. You should see the version of Node.js that was installed, something like this:
    v16.16.0
    Code language: JavaScript (javascript)

    Uninstalling the Node.js in Windows

    There are actually three ways through which we can remove Node.js from our windows system. Let’s have a look at each of them.

    Method 1: Uninstalling from Windows Settings

    • Go to Settings by searching it in the start menu.
    • Click on the Apps section.
    • Look for the search box under Apps & Features section, and enter Nodejs there.
    • Select on Nodejs application and click on uninstall.
    • It is recommended that you restart your Windows machine even if you aren’t prompted to do so.
    • Lastly, run cmd as administrator and type:
    node --version
    Code language: JavaScript (javascript)

    • If you see an output like this: then Node is successfully uninstalled from your computer.

    Method 2: Uninstalling from Windows CMD

    • Search for “ cmd ” in the start menu. Right-click on it and select “Run as administrator“.
    • Or, Press Win+R to open “run“. Enter “ cmd ” and hit Ctrl+Shift+Enter to open the command prompt as administrator.
    • Run the following command in your terminal to clear your npm cache:
    npm cache clean --force
    Code language: JavaScript (javascript)
    • Now, to remove Node.js and npm successfully:
      • Go to the windows control panel.
      • Select Uninstall a program.
      • Right-Click on Nodejs and uninstall.
      • Lastly, run cmd as administrator and type:
      node --version
      Code language: JavaScript (javascript)

      • If you see an output like this: then Node is successfully uninstalled from your computer.

      Method 3: Uninstalling from Windows Registry

      • Search for “ Registry Editor ” in the start menu and click on it.
      • Or, Press Win+R to open “run“. Enter “ regedit ” and hit Enter to open the Windows Registry.
      • A prompt will open asking you to allow the app to make changes. Click Yes.
      • You can either go to the path below or paste it in the path field: ComputerHKEY_LOCAL_MACHINESOFTWARENode.js
      • As a next step, locate the Nodejs directory on the left sidebar. Right-click on it and delete the directory.
      • It is recommended that you restart your Windows machine even if you aren’t prompted to do so.
      • Lastly, run cmd as administrator and type:
      node --version
      Code language: JavaScript (javascript)

      • If you see an output like this: then Node is successfully uninstalled from your compute

      Uninstalling the Node.js in Ubuntu

      We will examine multiple options to uninstall NodeJS in Ubuntu using the three typical commands: uninstall, remove and purge.

      Step 1: Locating the Binary Files

      You can locate the folder where NodeJS binaries are located and verify if it’s uninstalled as well. This can be done using the which or find command as shown below:

      $ which node $ find $(echo $PATH | sed 's/:/ /g') -name "node"
      Code language: JavaScript (javascript)
      $ find / -name "node"
      Code language: JavaScript (javascript)

      You should see an output similar to this if the node is installed:

      /user/bin/node /user/bin/node
      Code language: JavaScript (javascript)
      /user/bin/node /user/share/doc/node /user/share/code/resources/app/extensions/emmet/dist/node /user/share/code/resources/app/extensions/css-language-features/server/dist/node /user/share/code/resources/app/extensions/css-language-features/client/dist/node /user/share/code/resources/app/extensions/ms-vscode.js-debug/src/targets/node /user/share/code/resources/app/extensions/html-language-features/server/dist/node /user/share/code/resources/app/extensions/html-language-features/client/dist/node /user/share/code/resources/app/extensions/json-language-features/server/dist/node /user/share/code/resources/app/extensions/json-language-features/client/dist/node /user/share/code/resources/app/out/vs/workbench/api/node /user/share/code/resources/app/out/vs/workbench/contrib/debug/node /user/share/code/resources/app/out/vs/workbench/contrib/externalTerminal/node /user/share/code/resources/app/out/vs/base/node /user/share/code/resources/app/out/vs/platform/files/node /user/share/code/resources/app/out/vs/platform/environment/node /user/share/code/resources/app/out/vs/platform/terminal/node j/user/share/code/resources/app/out/vs/code/node /user/include/node
      Code language: JavaScript (javascript)

      Step 2: Uninstalling NodeJS

      Now, there are different ways of removing Nodejs from the system. Let’s look at some of the options below:

      Method 1: Removing the binary paths

      We can discard Nodejs by manually deleting the binaries we located in the previous step, although this method is less recommended than others.

      $ sudo rm /user/bin/node
      Code language: JavaScript (javascript)
      Method 2: Use the apt or apt-get command to Uninstall

      The most commonly used commands in Ubuntu to uninstall NodeJS are apt and apt-get.

      $ sudo apt-get remove nodejs
      Code language: JavaScript (javascript)

      The above command only removes the package. In order to remove all the node-related packages as well, see the methods in step 4.

      Method 3: Uninstalling a Particular version of NodeJS

      Suppose you want to uninstall only a specific version of NodeJS. You can use the below command to remove that version only. Eg:

      $ nvm uninstall 16.16.0
      Code language: JavaScript (javascript)

      You should see an output like this:

      Uninstalled node v16.16.0
      Code language: JavaScript (javascript)

      Step 3: Removing NodeJS info from the Source Lists

      After removing NodeJS, check to see if there is any NodeJS data present in the /etc/apt/sources.list.d directory:

      $ ls /etc/apt/sources.list.d
      Code language: JavaScript (javascript)

      You should see folders named nodesource.list and nodesource.list.distUpgrade. If not present then your NodeJS information is removed from the sources list. Otherwise, Use the below command to remove them:

      $ rm -rf nodesource.list nodesource.list.distUpgrade
      Code language: JavaScript (javascript)

      Last but not the least, make sure to update the Ubuntu repositories.

      $ sudo apt-get update
      Code language: JavaScript (javascript)

      Step 4: Clearing the Cache

      NodeJS can sometimes leave traces of some packages and modules after uninstalling. You can use any of the following methods to remove all the node-related packages as well as the configuration files.

      Method 1: Using the purge command

      The purge command helps us remove all these packages and files. Use any of the two commands below:

      $ sudo apt-get purge nodejs
      Code language: JavaScript (javascript)
      $ sudo apt-get purge – auto-remove nodejs
      Code language: JavaScript (javascript)
      Method 2: Removing npm manually

      You can manually remove the hidden npm directories and other related files using the below commands:

      $ ls -la $ rm -rf .npm
      Code language: JavaScript (javascript)

      Step 5: Remove Unused Files

      The last step is to run the following command to get rid of unused files and free up the space on your computer.

      $ sudo apt-get autoremove
      Code language: JavaScript (javascript)

      Uninstalling the Node.js on Mac

      Now, let’s look at some of the ways to uninstall Node.js from MacOS as well.

      Method 1: Uninstalling using homebrew

      • Click on the search icon in the menu bar or press command + space to launch the spotlight.
      • Type terminal and hit Return .
      • Run this command to uninstall all versions of Node from your mac.
      # brew uninstall --force node
      Code language: JavaScript (javascript)
      • Once that’s done, type the following command to remove unused folders and dependencies.
      # brew cleanup
      Code language: JavaScript (javascript)

      Method 2: Uninstalling using NVM

      • Click on the search icon in the menu bar or press command + space to launch the spotlight.
      • Type terminal and hit Return .
      • To uninstall the node with the help of nvm, type the following command, replacing with the current version of your node installed. Eg: v16.16.0.
      # nvm uninstall
      Code language: JavaScript (javascript)

      Method 3: Uninstalling using terminal

      • Click on the search icon in the menu bar or press command + space to launch the spotlight.
      • Type terminal and hit Return .
      • Once the terminal is opened, enter the given below command:
      # sudo rm -rf /usr/local/,bin,share/man>/
      Code language: JavaScript (javascript)
      • The above command will not remove all of the packages. To delete every global package you have installed using npm, run the below command:
      # rm –rf ~/.npm
      Code language: JavaScript (javascript)

      Method 4: Uninstalling Node Manually

      • From the Dock, select the Go menu and then Folder from the Finder icon.
      • In the text box, paste the directory path: /usr/local/lib
      • Then move any files that have the name ‘node’ to the Trash.
      • Paste each of the following paths into the text box in Go to Folder and drag the files with the name ‘node’ to the Trash.
      /usr/local/bin /usr/local/include /usr/local/share/man/man1/ /usr/local/lib/dtrace/ /opt/local/bin/ /opt/local/include/ /opt/local/include/ /usr/local/share/doc/ /usr/local/share/systemtap/tapset/
      Code language: JavaScript (javascript)
      • Drag the following files in the Home folder to the Trash: .npm, .node-gyp, .nodereplhistory .
      • Lastly, empty the Trash.

      Conclusion

      That was pretty much it! Hopefully, you can now successfully uninstall NodeJS from your computer.

      If you ever feel lost and want help understanding where to start your coding journey then go check out Codedamn. There are amazing courses and blogs for web development and other coding concepts. Remember to practice coding on a daily basis. You can play around with your code on Codedamn’s online compiler as well

      Let us know in the comments if you have any suggestions or queries. Finally, If you are interested in my content and would like to connect, then you can find me on Linkedin or Twitter.

      Become The Best Full-Stack Developer ��

      Codedamn is the best place to become a proficient developer. Get access to hunderes of practice Node.js courses, labs, and become employable full-stack web developer.

      Unlimited access to all platform courses

      100+ practice projects included

      ChatGPT Based Instant AI Help

      Structured Node.js Full-Stack Roadmap To Get A Job

      Exclusive community for events, workshops

      Sharing is caring

      Did you like what Indrakant wrote? Thank them for their work by sharing it on social media.

      Добавление и удаление пакетов с помощью npm или Yarn

      Yarn

      Одна из лучших особенностей открытого кода и экосистем современных языков программирования заключается в том, что код, который вы собираетесь написать, вероятнее всего, уже написан и готов к использованию.

      Для Node.js уже написано множество пакетов, и обычно эти пакеты созданы умными и опытными людьми, которые продумали кучу вещей, о которых менее опытный разработчик мог не подумать.

      В этом мануале мы обсудим работу с инструментами npm и yarn. Обе эти команды довольно популярны, вы могли сталкиваться с ними в других статьях по Node.js. Если же вы никогда не слышали о них: npm и yarn – это менеджеры пакетов для Node.js. Оба они используют файл package.json и работают очень похожим образом.

      Если у вас уже есть локальная установка Node.js, вероятно, у вас установлен и npm. Если вы предпочитаете использовать yarn, но у вас нет этой команды, вы можете ознакомиться с инструкциями по установке yarn здесь.

      В зависимости от вашей системы вы также можете установить эти команды с помощью вашего менеджера пакетов.

      Кроме того, некоторые пакеты мы будем устанавливать глобально, а другие – как зависимость проекта. Для работы с этим мануалом можно использовать уже существующий проект или создать простой тестовый проект в каталоге /tmp, например:

      $ mkdir /tmp/gator-project
      $ cd /tmp/gator-project
      $ npm init -y

      Эти команды создают файл package.json, в который мы будем добавлять и удалять пакеты.

      Добавление зависимости разработки в проект

      Не все зависимости одинаковы – некоторые из них требуются только при разработке. Эти зависимости тоже важны, но в производстве они могут замедлить развертывание, поскольку для их установки требуется время.

      В качестве примера зависимостей разработки можно привести утилиты тестирования типа mocha или jest. Такие пакеты мы можем установить как зависимости разработки и добавить в раздел devDependencies нашего файла package.json:

      # NPM
      $ npm install —save-dev mocha
      # сокращенная версия
      $ npm i -D mocha
      # Yarn
      $ yarn add —dev mocha
      # сокращенная версия
      $ yarn add -D mocha

      Добавление зависимостей производства в проект

      Некоторые зависимости критически важны для приложения и всегда должны устанавливаться независимо от среды – и в разработке, и в производстве без них никуда. Это зависимости производства, обычно к ним относятся такие пакеты, как express или react.

      Добавить зависимость производства в проект так же просто, как и зависимости разработки, но вместо devDependencies их следует помещать ​​в раздел dependencies:

      # NPM
      $ npm install —save express
      # сокращенная версия
      $ npm i -P express
      # Yarn
      $ yarn add express

      Глобальная установка зависимостей

      Иногда бывает необходимо установить пакет вне текущего проекта, чтобы он был доступен для всех проектов в текущей системе. Такие пакеты устанавливаются глобально. Чаще всего они включают утилиты, которые необходимо запускать вместе с другими утилитами командной строки:

      # NPM
      $ npm install —global json
      # сокращенная версия
      $ npm i -g json
      # Yarn
      $ yarn global add json

      Удаление зависимости из проекта

      В жизни каждого проекта наступает момент, когда зависимость, которая когда-то казалась жизненно необходимой, больше не выполняет никакой функции. В таком случае всегда лучше удалить код (при условии, что вы все хорошо протестировали и уверены, что после удаления ничего не сломается).

      Чтобы удалить из проекта зависимость разработки или производства, используйте:

      # NPM
      $ npm uninstall jest
      # Shorthand version
      $ npm r jest
      # Yarn
      $ yarn remove jest

      Это удалит пакеты из node_modules, а также уберет зависимость из package.json. Некоторые версии этих команд также показывают обновления файла.

      Глобальное удаление пакета

      Удаление глобально установленного пакета выполняется так же, как удаление пакета из проекта, только вы должны передать аргумент global (его же мы использовали при глобальной установке).

      # NPM
      $ npm uninstall —global json
      # сокращенная версия
      $ npm r -g json
      # Yarn
      $ yarn global remove json

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *