龙芯npm的安装和仓库配置使用
npm介绍
NPM的全称是Node Package Manager,是一个NodeJS包管理和分发工具,能解决NodeJS代码部署上的很多问题。npm仓库(registry)中存放所有需要被共享的js代码,每个js文件都有自己唯一标识。用户想使用某个js的时候,只需引用对应的标识,js文件会自动下载下来。常见的使用场景有以下几种:
npm的安装
在Debian系下安装:
[test@bogon:~]$ sudo apt install npm
在RedHat系下安装:
[test@bogon:~]$ sudo dnf install npm
配置龙芯官方npm仓库:
如下配置龙芯官方的npm仓库:
## 配置普通用户npm仓库
[test@bogon:~]$ npm config set registry https://registry.loongnix.cn:4873
## 配置root用户npm仓库
[test@bogon:~]$ sudo npm config set registry https://registry.loongnix.cn:4873
registry 后接你想要使用的npm的仓库地址
查看npm使用的仓库源:
## 查看普通用户仓库地址
[test@bogon:~]$ npm config get registry
https://registry.loongnix.cn:4873
## 查看root用户仓库地址
[test@bogon:~]$ sudo npm config get registry
https://registry.loongnix.cn:4873
如上所示,就会显示目前所使用的仓库地址。
npm的使用
npm安装包分为本地安装,全局安装两种(以安装echo为例):
本地安装: [test@bogon:~]$ npm install echo
全局安装: [test@bogon:~]$ sudo npm install echo -g
如果想要下载指定版本的话,可以在包名后边加上@
本地安装:[test@bogon:~]$ npm install echo@0.1.9
全局安装:[test@bogon:~]$ sudo npm install -g echo@0.1.9
判断此时系统环境信息和js相关软件版本
查看 nodejs 版本
[test@bogon:~]$ node -v
v14.16.1
查看 nodejs的os.arch
[test@bogon:~]$ node
Welcome to Node.js v14.16.1.
Type ".help" for more information.
> os.arch()
'loong64'
>