- 首先从官网下载nexus 安装包。
寻找最新版本的安装包,根据系统下载对应的安装包
![](https://img-blog.csdnimg.cn/img_convert/6bd26a2fd1e9ff7143821ce94bae54a2.png)
以windows为例下载中间的windows archive 压缩包,放到系统中的磁盘上,然后解压安装包。
解压后的目录为
![](https://img-blog.csdnimg.cn/img_convert/27d5a82b47a8cab2551f182be80ffd7b.png)
在nexus-3.19.1-01\bin目录下打开cmd,输入命令 .\nexus.exe /run启动Nexus。
在浏览器中打开localhost:8081,第一次登录admin时,会提示密码在/sonatype-work/nexus3/admin.password里,打开文件复制密码登录,然后会提示重置密码。依次操作即可。
- 配置npm仓库
创建npm仓库,分为三类,npm(group)、npm(hosted)、npm(proxy)
在创建仓库之前先配置下存储位置,最好单独创建一个位置,与默认位置区分开以便以后maven等区分。
选择bolb Stores 点击create blob store 按钮弹出如下图页面,类型选择flie,自定义名称,存储位置,后边在创建仓库是使用。
![](https://img-blog.csdnimg.cn/img_convert/05bfc4850645dd132c35efdbdfb2352a.png)
配置国内仓库代理,
![](https://img-blog.csdnimg.cn/img_convert/123676f8dc84af0c3bf6eed1bcb95329.png)
国内仓库地址:https://registry.npmmirror.com
官方仓库地址:https://registry.npmjs.org/
选择npm(proxy)进入配置页面,输入名称,代理地址,选择blob store选择自定义的Store
![](https://img-blog.csdnimg.cn/img_convert/083c02c5a182f46f8a405798227b439b.png)
配置好相应参数,点击create repository按钮。完成创建。
创建npm(hosted)本地仓库,和上边步骤一样,选择npm(hosted)完成相关字段参数配置。点击创建按钮完成创建
![](https://img-blog.csdnimg.cn/img_convert/476fdd3f090f50b649d8ed73df7f053b.png)
创建npm(group)仓库
![](https://img-blog.csdnimg.cn/img_convert/68c60208e6b9c8f23eb3570965eeb089.png)
npm仓库配置成功后,本地npm配置修改为group仓库地址。之后在下载的依赖,会换缓存在本地仓库中。
配置权限
![](https://img-blog.csdnimg.cn/img_convert/88614c7b74595abfb466000eb7046d8e.png)
该步骤非常重要,否则在adduser和publish会一直报错401:Unable to authenticate, need: BASIC realm=“Sonatype Nexus Repository Manager”。
- 发布npm包
创建一个测试目录,在目录中打开cmd 输入npm init -y初始化,会创建一个package.json文件,然后创建一个index.js文件,里边简单写一个函数,
function getdata(){
return {data: '12345sdf'}
}
module.exports = getdata;
注册hosted仓库
npm adduser --registry=http://localhost:8081/repository/npm-hosted/回车,会让输入用户名,密码,邮箱等信息,
在package.json和index.js目录下打开cmd,输入npm publish --registry=http://localhost:8081/repository/npm-hosted/
上传npm包,然后在browse,htmlView 中就可以看到上传的安装包版本文件了
![](https://img-blog.csdnimg.cn/img_convert/8c151cc381938b23860048cb3dc96963.png)
- 安装npm
配置npm指向本地仓库npm config set registry http://localhost:8081/repository/npm-group/
在项目中输入执行 npm install packaget安装。