search
HomeWeb Front-endJS TutorialShare how to install npm using the latest version of nodejs

Share how to install npm using the latest version of nodejs

Jan 19, 2018 am 09:19 AM
javascriptnodejsInstructions

This article mainly introduces the detailed explanation of the use of npm for installing the latest version of nodejs. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

# Install nodejs

The following is the command line installation method. Readers can also download and install it from the nodejs official website.


sudo apt-get install nodejs-legacy
sudo apt-get instatll npm

Upgrade npm to the latest version


sudo npm install npm@latest -g

Often nodejs installed using the command line is not the latest version, and upgrade Nodejs is not a very simple thing; at this time we need to use the very easy-to-use nodejs version management module n


sudo npm install -g n

to install the specified version of nodejs through module n


sudo n latest
sudo n stable
sudo n lts

We can check whether the installation is successful and whether it is installed to the desired version by looking at the version number


node -v
npm -v

# Talk about npm

1. npm (node ​​package manage) is the package manager of nodejs. It is used for the management of node plug-ins, including installation, uninstallation, dependency management, etc.

2 , use npm to install the plug-in, the syntax is; npm install [-g] [--save-dev]

2,1 : The name of the plug-in to be managed, for example : npm install gulp-less --save-dev
2.2 -g: Global installation. Optional, if not added, the plug-in will be installed in the node_modules folder of the current location directory. The advantage of global installation is that it can be called from anywhere via the command line.

2.3 --save: Save configuration information to the package.json file. package.json is the configuration file of the nodejs project.

2.4 -dev: Save to the devDependencies node of package.json. If -dev is not added, it will be saved to the dependencies node.

2.5 Why should we save it to package.json? Because the node plug-in package is very large, version management is not included. Adding the configuration information to package.json can indicate that these plug-ins require version management. When browsing or using other developers, you can understand which version of the plug-in should be used. At the same time, use npm intstall will download the required packages according to the content specified in package.json during installation. In addition, using npm install --production will only download the package of the dependencies node in package.json

3. Use npm to uninstall the plug-in. The syntax format is: npm uninstall [-g][--save -dev]

3.1 Do not delete the plug-in package directly locally

3.2 Delete all plug-ins, the syntax is: npm uninstall gulp-less gulp-gulify gulp-concat...
3.3 One-time deletion with rimraf: npm install rimraf -g, usage rimraf node_modules

4. Use npm to update the plug-in, the syntax is: npm update [-g] [--save-dev]

4.1 Update all plug-ins: "npm update [--save-dev]

5. View npm help, the syntax is: npm help

6. View the To install the plug-in, the syntax is: npm list

# Select cnpm

  1. npm service is abroad, so it is greatly affected by the network and often appears. Abnormal, the Taobao team has made a complete npmjs.org mirror for this, and the version synchronization frequency is every 10 minutes. The official website address is: http://npm.taobao.org

  2. Install cnpm. Use the command npm install cnpm -g --registry=https://registry.npm.taobao.org. After the installation is complete, use cnpm -v to check whether the installation is successful.

  3. How to use cnpm and npm is completely the same, just change npm to cnpm

# Create a new package.json file

The package.json file is based on nodejs An essential configuration file for the project, it is saved in the root directory in the form of an ordinary json file.

The content and format are roughly as follows: (json files cannot be commented, be careful to delete them)


{
 "name": "test", // 项目名称(必须)
 "version": "1.0.0", // 项目版本(必须)
 "description": "project description!", // 项目描述(必须)
 "homepage": "", // 项目主页
 "repository": { // 项目资源库
  "type": "git",
  "url": "https://xxxx/xxx"
 },
 "author": { // 项目作者信息
  "name": "surging",
  "email": "xxx@163.com"
 },
 "license": "ISC", // 项目许可协议
 "devDependencies": { // 项目依赖的插件,加 -dev 安装会自动加到此处
  "gulp": "^3.8.11",
  "gulp-less": "^3.0.0"
 }
}

Create the package.json file, syntax npm init


cd ~/workspace/demo
npm init

Then follow the prompts step by step to fill in the following steps The information is as follows:

npm init

Then you can see that a package.json file is generated in the folder, and the printed information is as follows:

package.json information printing

Of course you can also create it manually, but I believe you will not do this.

4. View the package.json help document, the syntax is: cnpm help package.json

Related recommendations:

Update under windows Detailed explanation of the methods of npm and node

Detailed explanation of the method of nvm managing different versions of node and npm

Detailed explanation of examples of private npm packages

The above is the detailed content of Share how to install npm using the latest version of nodejs. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function