If you see an EACCES error when you try to install a package globally, you can either:

  • Reinstall npm with a node version manager (recommended),

or

  • Manually change npm’s default directory

Reinstall npm with a node version manager§

This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in “Downloading and installing Node.js and npm”. You do not need to remove your current version of npm or Node.js before installing a node version manager.

Manually change npm’s default directory§

Note: This section does not apply to Microsoft Windows.

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.

  1. Back up your computer.
  2. On the command line, in your home directory, create a directory for global installations:
     mkdir ~/.npm-global
  3. Configure npm to use the new directory path:
     npm config set prefix '~/.npm-global'
  4. In your preferred text editor, open or create a ~/.profile file and add this line:
     export PATH=~/.npm-global/bin:$PATH
  5. On the command line, update your system variables:
     source ~/.profile
  6. To test your new configuration, install a package globally without using sudo:
     npm install -g jshint

Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global
 
# 第一步:在你的用户文件下新建一个文件夹,这个.npm-global 名字可以用你自己喜欢的名字替换,推荐直接使用这个名字。
mkdir ~/.npm-global
#第二步:更改node的安装连接
npm config set prefix '~/.npm-global'
#第三步:在用户的profile下增加path,为的是系统能够找到可执行文件的目录
export PATH=~/.npm-global/bin:$PATH
#第四步:update profile。使其生效
source ~/.profile


Resolving EACCES permissions errors when installing packages globally(npm 遇到 write access的问题)的更多相关文章

  1. xp安装vmware10时一直停在installing packages on the system

    我估计的原因是: vm会在网上邻居(LAN或高速internet)下创建两个 vmware network adapter vmnet8 vmware network adapter vmnet1   ...

  2. Install packages failed: Installing packages: error occurred. ------简单的问题常常会被忽略

    用 pip install 安装了wxpy这个库,但是使用的时候却报错:ImportError: No module named wxpy 我先用 pip list 查看了一下,发现这个库是已经存在的 ...

  3. [NPM] Publish npm packages using npm publish

    In this lesson we will publish our package. We will first add a prepublish script that runs our buil ...

  4. NPM全局安装软件包时解决EACCES权限错误

    NPM全局安装软件包时解决EACCES权限错误 Resolving EACCES permissions errors when installing packages globally npm WA ...

  5. 解决Mac下npm权限问题

    前言 在学习Vue-CLI3的时候使用了全局安装,提示安装失败,本以为是npm版本问题,在更新npm的过程中又出现了 npm ERR! code: 'EACCES' ,查了一下发现是权限问题. 看到权 ...

  6. npm install 权限问题

    npm ERR! Error: EACCES: permission denied, access '/Users/Lobin/work/note-vue/node_modules/@babel/hi ...

  7. Getting Started With Node and NPM

    Getting Started with Node and NPM Let's start with the basics. Install Node.js: https://nodejs.org.

  8. [TypeScript] Using Typings and Loading From node_modules

    Using TypeScript when installing packages from npm often requires you to install related definition ...

  9. browserify总结

    一.browserify 简介 browserify is a tool for compiling node-flavored commonjs modules for the browser. Y ...

随机推荐

  1. FindWindow SendMessage

    FindWindow 用来根据类名和窗口名来得到窗口句柄的.但是这个函数不能查找子窗口,也不区分大小写. 如果要从一个窗口的子窗口中查找需要使用FindWindowEX. 1.在C#中使用方法如下: ...

  2. git下,输入git log 进入log 怎么退出

    解决方案: 英文状态下按Q就可以了 ctrl + c (应该是Linux命令中断的意思,很多中断都是这个命令). Paste_Image.png

  3. tkinter 按钮响应函数传值

    tkinter 中的Button组件的响应函数如何传入参数,可能非常困扰新手,这里记录一下. 步骤: 1. 写好响应函数(形参设置好) 2. 在Button command 设置形式:command ...

  4. 一段让人瑟瑟发抖的ABAP代码

    昨天11月1日是万圣节,Jerry在继续忙着调研SAP Commerce Cloud里的产品主数据管理.晚上回家到SAP国外的社交媒体上一看,好热闹啊.国外的SAP从业者们纷纷以各种各样的方式庆祝万圣 ...

  5. 1-Spark-1-性能调优-数据倾斜1-特征/常见原因/后果/常见调优方案

    数据倾斜特征:个别Task处理大部分数据 后果:1.OOM;2.速度变慢,甚至变得慢的不可接受 常见原因: 数据倾斜的定位: 1.WebUI(查看Task运行的数据量的大小). 2.Log,查看log ...

  6. Kubernetes-Istio之Sidecar自动注入

    前提: (官方提供) 1):确认使用的是Kubernetes服务器的受支持版本( 1.13.1.14.1.15):kubectl (官方提供,应该是1.13版本以上,我的是1.16版本) kubect ...

  7. CDH构建大数据平台-使用自建的镜像地址安装Cloudera Manager

    CDH构建大数据平台-使用自建的镜像地址安装Cloudera Manager 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一.搭建CM私有仓库 详情请参考我的笔记: http ...

  8. HashMap简介以及hashCode写法的建议

    映射表Map Map也叫映射表或者字典,Map中存储的元素是一个键值对key-value,他们共同包装在Entry<K,V>对象中.我们能通过key直接获取value,就像查字典一样. J ...

  9. Replica set 的选举策略之一 (转)

    首先介绍一下在replica set里分为三种节点类型: 1 primary   负责client的读写. 2 secondary 作为热备节点,应用Primary的oplog读取的操作日志,和pri ...

  10. markdown种嵌入html标签,实现自定义样式

    转:https://www.cnblogs.com/buwuliao/p/9578918.html -------------------------------------------------- ...