Linux 中使用 verdaccio 搭建私有npm 服务器

安装 Node

Linux中安装Node

安装verdaccio

bash 复制代码
npm i -g verdaccio

安装完成 输入verdaccio,出现下面信息代表安装成功,同时输入verdaccio后verdaccio已经处于运行状态,当然这种启动时暂时的,我们需要通过pm2让verdaccio服务常驻

bash 复制代码
   yg@iZ2zec61wsgbo9t9i346jbZ:~$ verdaccio
   warn --- config file  - /home/yg/.config/verdaccio/config.yaml
   warn --- Plugin successfully loaded: htpasswd
   warn --- Plugin successfully loaded: audit
   warn --- http address - http://localhost:4873/ - verdaccio/3.10.1

配置config.yaml

shell 复制代码
1、vim /home/yg/.config/verdaccio/config.yaml 进入编辑配置文件

# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#

# path to a directory with all packages
# 所有包缓存的目录
storage: ./storage
# path to a directory with plugins to include
# 插件目录
plugins: ./plugins

# 开启web服务,能够通过web访问
web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  #enable: false
  title: Verdaccio

# 验证信息
auth:
  htpasswd:
    # 用户信息存储目录
    file: ./htpasswd
    # Maximum amount of users allowed to register, defaults to "+inf".
    # You can set this to -1 to disable registration.
    #max_users: 1000

# a list of other known repositories we can talk to
# 公有仓库配置
uplinks:
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    # 代理,表示没有的仓库去这个npmjs里边去找
    # npmjs 又指向 https://registry.npmjs.org/ ,就是上面的 uplinks 配置
    proxy: npmjs

  '**':
    # allow all users (including non-authenticated users) to read and
    # publish all packages
    #
    # you can specify usernames/groupnames (depending on your auth plugin)
    # and three keywords: "$all", "$anonymous", "$authenticated"
    # 三种身份所有人,匿名用户,认证(登录用户)
    # 是否可访问所需的权限
    access: $all

    # allow all known users to publish packages
    # (anyone can register by default, remember?)
    # 发布package的权限
    publish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    # 如果package不存在,就向代理的上游服务器发起请求
    proxy: npmjs

# To use `npm audit` uncomment the following section
middlewares:
  audit:
    enabled: true

# 监听端口,重点,不配置这个只能本机可以访问
listen: 0.0.0.0:4873

# log settings
logs:
  - {type: stdout, format: pretty, level: http}
  #- {type: file, path: verdaccio.log, level: info}

安装 pm2

bash 复制代码
npm i pm2 -g

启动

bash 复制代码
pm2 start verdaccio  

就可以通过http://xxx(ip地址)去访问了

设置 npm 服务指向本地

bash 复制代码
npm config set registry http://localhost:4873

注册用户

bash 复制代码
# 注册用户 在本地注册一个用户然后指向我们的地址然后我们就可以发布包了
npm adduser --registry http://xxx:4873
Username: xxx
Password: xxx
Password:  xxx
Email: (this IS public) xxx
Logged in as yg-ui on http://xxx/ (你的ip地址)
这时候我们就注册一个用户,我们可以用这个用户名和密码去登录去上图窗口去登录了

登录

bash 复制代码
npm login 	# 用刚刚注册的用户名密码进行登录
npm whoami	# 查看当前登录的账号

发包

bash 复制代码
mkdir npm-publish-test	# 包文件夹
cd npm-publish-test
npm init				# npm初始化
npm publish	

删除 指定版本或包

bash 复制代码
$ npm unpublish [<pkg>][@<version>] --force

下面列一下几种使用场景

  • $ npm unpublish dzmtest@1.0.1 --force

    直接强制删除指定包的指定版本,不需要 cd 进入包文件夹内,随处可以执行。

  • $ npm unpublish dzmtest --force

    直接强制删除指定包,不需要 cd 进入包文件夹内,随处可以执行。

相关推荐
广药门徒7 分钟前
Linux驱动开发与BuildRoot是什么关系与其的应用场景
linux·运维·驱动开发
czhc114007566315 分钟前
Linux108 shell:.bashrc 正则表达式:. * .* ^ $ ^$ [ ] [^] ^[] ^[^ ] \< \>
linux·正则表达式
野猪疯驴20 分钟前
Linux shell学习(更新中....)
linux·shell
努力学习的小廉37 分钟前
深入了解linux网络—— TCP网络通信(下)
linux·网络·tcp/ip
Lu Zelin7 小时前
单片机为什么不能跑Linux
linux·单片机·嵌入式硬件
CS Beginner8 小时前
【Linux】 Ubuntu 开发环境极速搭建
linux·运维·ubuntu
ajassi20008 小时前
开源 C++ QT QML 开发(二)工程结构
linux·qt·qml
今天只学一颗糖9 小时前
Linux学习笔记--insmod 命令
linux·笔记·学习
摩羯座-1856903059410 小时前
爬坑 10 年!京东店铺全量商品接口实战开发:从分页优化、SKU 关联到数据完整性闭环
linux·网络·数据库·windows·爬虫·python
irisart10 小时前
4.1 > Linux 文件/目录权限管理【理论】
linux