npm下载安装教程
nodejs
is a popular javascript platform and framework which provides server and client-side libraries. What makes nodejs so successful is its package manager named npm
or nodejs package manager. npm provides easily install, update and remove packages and load libraries according to the application configuration.
nodejs
是流行的javascript平台和框架,提供服务器和客户端库。 使nodejs如此成功的原因是其名为npm
软件包管理器或nodejs软件包管理器。 npm可根据应用程序配置轻松安装,更新和删除软件包以及加载库。
为Ubuntu,Debian,Mint,Kali安装Npm软件包 (Install Npm Package For Ubuntu, Debian, Mint, Kali)
We can install npm
package with the apt
command where Ubuntu, Debian, Mint, Kali distributions support.
我们可以使用apt
命令安装npm
软件包,其中支持Ubuntu,Debian,Mint,Kali发行版。
$ sudo apt install npm
为Fedora,CentOS,RedHat安装Npm软件包(Install Npm Package For Fedora, CentOS, RedHat)
For yum
based distributions we will use yum
or dnf
command like below where we will install npm
package.
对于基于yum
的发行版,我们将使用yum
或dnf
命令(如下所示)在其中安装npm
软件包。
$ sudo yum install npm
OR
要么
$ sudo dnf install npm
打印npm一般帮助信息(Print npm General Help Information)
npm command provides different type of commands or options in order to manage nodejs packages. We can get general information about these command with the -h
option.
npm命令提供了不同类型的命令或选项,以管理nodejs软件包。 我们可以使用-h
选项获得有关这些命令的常规信息。
$ npm -h
获取npm的特定命令或选项帮助(Get Specific Command or Option Help For npm)
In the previous example, we have listed generic information about the npm commands and options. We may need a more detailed help about these commands or options which can be listed with the COMMAND -h
. In this example, we will list detailed help about the search
command.
在前面的示例中,我们列出了有关npm命令和选项的一般信息。 关于这些命令或选项,我们可能需要更详细的帮助,这些命令或选项可以与COMMAND -h
一起列出。 在此示例中,我们将列出有关search
命令的详细帮助。
$ npm search -h
使用npm搜索A软件包(Search For A Packages with npm)
We can search for a specific package for installation with the search
command or option. In this example, we will search the term angular
.
我们可以使用search
命令或选项search
要安装的特定软件包。 在此示例中,我们将搜索术语angular
。
$ npm search angular
We can see that search results are printed and listed in a structured column. This search results will present the following information.
我们可以看到搜索结果已打印并列在结构化列中。 该搜索结果将显示以下信息。
NAME
is the package full name likeangular
,angular-strap
etc.NAME
是软件包的全名,例如angular
,angular-strap
等。DESCRIPTION
is the info about the package what is it.DESCRIPTION
是有关包装信息的信息。AUTHOR
is the package creator’s name or team name.AUTHOR
是包创建者的名称或团队名称。DATE
is the last time the package is updated.DATE
是软件包的最后更新时间。VERSION
is the version number of the package which is the latest.VERSION
是软件包的最新版本号。KEYWORDS
are some tags that describe and related to the package.KEYWORDS
是一些描述软件包并与软件包相关的标签。
使用npm安装单个软件包 (Install Single Package with npm)
We can install packages with the install
npm command or options by providing the package full name. In this example, we will install the package named angular
.
我们可以通过提供软件包全名来使用install
npm命令或选项来安装软件包。 在此示例中,我们将安装名为angular
的软件包。
$ npm install angular
We can see that after the package installation is complete the installed package name with is angular
and the version installed which is 1.7.8
are printed to the console.
我们可以看到,在软件包安装完成后,已安装的软件包名称(带有angular
和已安装的版本1.7.8
被打印到控制台。
使用npm在package.json中安装所有项目依赖项 (Install All Project Dependencies in package.json with npm)
package.json
provides the list of the packages which is required for a project. In order to run this project, the packages should be installed. npm
command can install packages listed in this package.json
easily.
package.json
提供了项目所需的软件包列表。 为了运行此项目,应安装软件包。 npm
命令可以轻松安装此package.json
列出的软件包。
{
"name": "node-js-sample",
"version": "0.2.0",
"description": "A sample Node.js app using Express 4",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.13.3"
},
"engines": {
"node": "4.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/heroku/node-js-sample"
},
"keywords": [
"node",
"heroku",
"express"
],
"author": "Mark Pundsack",
"contributors": [
"Zeke Sikelianos <[email protected]> (http://zeke.sikelianos.com)"
],
"license": "MIT"
}
We can simply use install
command which will automatically look for package.json
and install the required packages.
我们可以简单地使用install
命令,它将自动查找package.json
并安装所需的软件包。
$ npm install
使用npm更新软件包 (Update Packages with npm)
Updating packages with the npm is easy as installing them. We will provide the package name we want to update to the update
command or option. In this example, we will update the package named angular
.
使用npm更新软件包就像安装它们一样容易。 我们将要更新的包名称提供给update
命令或选项。 在此示例中,我们将更新名为angular
的包。
$ npm update angular
更新nmp (Update nmp)
npm can install and update different JavaScript libraries. npm can also update itself like a normal package. We will use i
option and provide the package name as npm
like below.
npm可以安装和更新不同JavaScript库。 npm也可以像普通软件包一样进行自我更新。 我们将使用i
选项,并将软件包名称提供为npm
如下所示。
$ npm i npm
We can see from the output that the current version is updated to the 6.9.0 .
从输出中我们可以看到当前版本已更新为6.9.0。
使用npm打印软件包详细信息 (Print Package Details with npm)
npm package information can be listed with the info
or view
command. We will also provide the package name. In this example, we will list and print information about the angular
package.
可以使用info
或view
命令列出npm软件包信息。 我们还将提供包裹名称。 在此示例中,我们将列出并打印有关angular
包的信息。
$ npm info angular
We can see that the following information about the package is provided.
我们可以看到提供了有关该软件包的以下信息。
name
is the package full name.name
是程序包的全名。description
is short information about the package.description
是有关包装的简短信息。latest
is the latest version of the package.latest
是软件包的最新版本。readmeFilename
is the name of the README.readmeFilename
是自述文件的名称。homepage
is the official home page of the package.homepage
是程序包的官方主页。keywords
is related tags and keywords with the package.keywords
是与程序包相关的标签和关键字。license
is a usage license.license
是使用许可证。
翻译自: https://www.poftut.com/npm-download-install-and-usage-tutorial/
npm下载安装教程