解决全局安装包时的 EACCES 权限错误

如果您在尝试 全局安装包 时看到 EACCES 错误,您可以:

  • 使用 node 版本管理器重新安装 npm(推荐),

    或者

  • 手动更改 npm 的默认目录

使用 node 版本管理器重新安装 npm

kTAp+j8eoQMOvDx8cl6/yvKgbcpqWI4zaV+sOTXok5e+/nJPZC8RaeVlonOCcdnSyP3Go5k8XU3c3ZnuLmIAFSnerb7Ps2zye1exPVKEROERcaitSStd/cRFGA3rWIX+v/Ts4T7lt4RDP6lZ3+aJZS2NT6mZ65DMM1gakKPqsND/X6S1RA16ZypA0sotjoAaW8bfltI8FK2VtxcmVNUiAk5vqot/RONn66cICXnchEksQpW7n2pVyN5Glze9rS/9o9q5GmwVOoj3h4STrQFW6vBitcQspugflqNEgABtoU1Z6LKh+49lRkqvD7EBzoahNtDwt8wwGmiSOovs1YPeznrxdKV2t/1SLLh87Czg1YbxOKQ/Vx16fM6EAK3Q+BvnKwsNJCfJyFQPkIHfjfK7yQ==

手动更改 npm 的默认目录

t6vAMn1DzH+hi+QDyi1bN3jdYWRcRG54aMyz7Ny0MWNy1UY9VqXDR8d5PgFw0viWKxBjHXXnMzqskQucnT3DjsEoWW4/TMviGU4Pt+Y6JoI=

BczXYiEgc2syv+KMmJ3c5S3WdbDQiFiHtKsuBN/ABplA6BmSNb4KUSq1QfE2T0D/q/9x5bRUUSCLzT1lBKGWmGAvQoPjCwv03vXQoxmRwqB8FVwoGeWwfr6Ay63D8UD+WbB2Eaify32hxu1AYuxfGvGUwnzRuJmWzvldjrdCvSQmICECcjDUiZiDyZeLd/nXYmRSlR2nuojGDnm+nspRjPBugT7QY16pS5NO1h4bbOY=

  1. HyCjey75EAsW5JI4EKmLDBULxtG6iPyOs3k7acLkpg4=

  2. teIWrTziZUXHKlH7Tb/OQaMSmROBD03FuOWLdGcfVC9OyZirbnZ7FpWfDG+pSRJ4Q2Dwr4XrmefNgk9kpBAsLSJPqFAhBJzeG39YAVC8Y1Y=

    mkdir ~/.npm-global
    
  3. xkjLGQ81LqsprHfrcIGVhmqQFicMtTwMwUMpzdGniKlXkYxEIoTODvV650XjL/rb

    npm config set prefix '~/.npm-global'
    
  4. HdmyBNvPpBgMvJEa0BwueAEZuUdVTZ26n0Md8y3tdxdwDAJ5aB0aj6r+xP0tMo3ELEe7xfP3sr4UM5rti5hLF8y8SDDUyoQyuhvlji+KHCgt5iaYjE5XSXQZIpvrlZjpOQ6IygLlCelYnbPDpw3esA==

    export PATH=~/.npm-global/bin:$PATH
    
  5. ++TQIc7OwEhhdwP10bLEBmnpsy1zsAH/viEAcRS8jfq0RnkxqlhUfwNGMecsjRl6

    source ~/.profile
    
  6. IQ8RWmIavOZmRx5Nq8IkcAHZaZ32HnVAAOgymLS0qwErj/MkGa0Be4ZLUtcB3z5IP8GeiVvAeJSnoqNnKSXJ2pWirhJkiSfBJGyYjVU6/W90cGrK0VtDhx/zBfvmTVvV1QVxW/NUXj5LPLpZdjCeQA==

    npm install -g jshint
    

kLCn0vGyR+xo/ZSoKetTccvU989v8MZ40eKhWsNErVbn6EbRhuQ0YqkKtwbQqAwndlJJ/twx1wDBu6vt4CXipJ9FQJ6vKRX2I0d1okI+V4yu9Yz6K5xVHcwMklhQMCh3NiGdat20hu2cMbvrdlTDheWWafT69jew14MZ+ILoBMA=

NPM_CONFIG_PREFIX=~/.npm-global

yHgt0M1A9VeOHenW063zU/liIOtM/SCXnCmA+f1vXgiHGG/D1g/pSO+7gvMIBb3F/Aivb8ay9nqOnSKviUVR3A==

CbP6BPoEJUPSeoE4oPPtQrMtzPdhOUz3+6mJtsl4nWRTE1JjNHIYkQn8AE23pLOrzuWF8qV2XdtMfhQDDv+W/oqP3CA3djJnSkUC952OFmsia1sjWcrzPY3fBsYDvznWN/a135WqYGO2gvLvq9ok9+8IdHYic2nNBNtOP/X11FvVE8y8fIi7Ho7OmKfkDvtHZF+Lt2NKB5c7qrlfKTNUJqh9Ly+kpEj+sz+c8ZEFL/5tyAsUffboKY2fyGvn0GUC/HWa3EEzwRNZyk7AyzaUYj6FCr+ucf9it664mRh3+KzkTeBrBmpyF5hienfQqMuR7uIeH1m8weDI7d7pV3WyAilWZn/+hF9dlST1AASM98cOlaWi7yyDYGKRhnqflOq+LMW0FKTrx4iFqiA3tL+YSYwXy0I0NwjhhxxfvktueZWmBrUXXKu42rkKMFbPhoYr