Jacobvu84 / selenium-vietnam-training-course

Questions Tracking
7 stars 5 forks source link

Resolving EACCES permissions errors when installing packages globally on Mac #54

Open Jacobvu84 opened 5 years ago

Jacobvu84 commented 5 years ago

docs.npmjs.com

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

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 appium 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
Jacobvu84 commented 5 years ago

Create .profile

export PATH=~/.npm-global/bin:$PATH

Create .bash_profile

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile"

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
export M2_HOME=$/usr/local/Cellar/maven/3.5.4
export ANDROID_SDK_ROOT=/Users/jacob/Library/Android/skd

PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/build-tools/28.0.2
Jacobvu84 commented 5 years ago

Create .npmrc

prefix=~/.npm-global