[Node] [npm] Installer le paquetage npm sur MacOS / Linux sans sudo

Install npm packages globally without sudo on macOS and Linux

npm installs packages locally within your projects by default. You can also install packages globally (e.g. npm install -g <package>) (useful for command-line apps). However the downside of this is that you need to be root (or use sudo) to be able to install globally.

Here is a way to install packages globally for a given user.

  1. Create a directory for global packages
mkdir "${HOME}/.npm-packages"
  1. Tell npm where to store globally installed packages
npm config set prefix "${HOME}/.npm-packages"
  1. Ensure npm will find installed binaries and man pages

Add the following to your .bashrc/.zshrc:

NPM_PACKAGES="${HOME}/.npm-packages"

export PATH="$PATH:$NPM_PACKAGES/bin"

# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"

If you're using fish, add the following to ~/.config/fish/config.fish:

set NPM_PACKAGES "$HOME/.npm-packages"

set PATH $NPM_PACKAGES/bin $PATH

set MANPATH $NPM_PACKAGES/share/man $MANPATH  

If you have erased your MANPATH by mistake, you can restore it by running set -Ux MANPATH (manpath -g) $MANPATH once. Do not put this command in your config.fish.


Check out npm-g_nosudo for doing the above steps automagically


NOTE: If you are running macOS, the .bashrc file may not yet exist, and the terminal will be obtaining its environment parameters from another file, such as .profile or .bash_profile. These files also reside in the user's home folder. In this case, simply adding the following line to them will instruct Terminal to also load the .bashrc file:

source ~/.bashrc

See also: npm's documentation on "Fixing npm permissions".

Original

https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md

Recommended Posts

[Node] [npm] Installer le paquetage npm sur MacOS / Linux sans sudo
Installez scipy sur Linux sans connexion Internet
Installez Minecraft sur Arch Linux
Installer Linux sur Chromebox
Installez JDK sur Linux
Installez tomcat 5.5 sur Amazon Linux.
Installation de Homebrew sur Amazon Linux 2
Installez Python Pillow sur Amazon Linux
Installer Oracle Java8 sur Amazon Linux2
Installez Arch Linux sur DeskMini A300
Comment installer Graph-Tool sur macOS
[Linux] Installez Python 3 sans privilèges d'administrateur
Comment installer VMware-Tools sur Linux
Installez l'AWS CLI v2 sans sudo
[Note] Installez Imagick sur Amzon Linux2
Installez PyStan sur Windows sans Anaconda
Installez Java2Python sur macOS High Sierra (10.13)
J'installe Ruby sur EC2 (Amazon Linux2) 2020
Comment installer aws-session-manager-plugin sur Manajro Linux
Installez wsl2 et master linux sous Windows
Installer et lancer k3s sur Manjaro Linux
Installer et configurer le serveur TigerVNC sous Linux
Comment installer des packages sur Alpine Linux
5 raisons d'installer Linux sur votre ordinateur portable.
Installez Python inférieur à 3.5.3 sur macOS Catalina
Dockerfile: installer Docker sur un serveur Linux
Comment installer php7.4 sur Linux (Ubuntu)
Installez rJava sur Linux dans un environnement R3.6.
Jusqu'à ce que vous installiez Arch Linux sur VMware
Installez Python 3.8, Pip 3.8 sur EC2 (Amazon Linux 2)
Résolution de l'erreur Linux «Install on / dev / sda»
Comment installer cx_Oracle sur macOS Sierra
Installer Linux Debian sur l'onglet Flèches Q584 / H
Installez Python 3.8.6 sur macOS BigSur à l'aide de pyenv
Exécutez l'installation de pip sur MacOS Python 3.7 ou version ultérieure
Installez Python 3 sur MacOS Catalina (avec Homebrew uniquement)
Comment installer Camunda Modeler sur Manjaro Linux
Installez PHP série 7 sur Amazon Linux 2 avec Amazon Linux Extras
Installer Python et les bibliothèques pour Python sur MacOS Catalina