Install NPM into home directory with distribution

2019-01-20 21:01发布

I'd like to use the distribution Node.js packages (or the chris-lea ppa for more recent releases) but install NPM to my home directory.

This may seem picky, but it's a pretty idiomatic way for polyglot/github-using developers to setup language runtime/library environments under Linux: distro packages for the runtime, 3rd-party libraries in per-user environment (see virtualenv, RVM - RVM will also build Ruby for you if you want). If necessary I will build node locally but it's a PITA since Node is becoming an incidental development requirement for lots of projects.

The second link seems like it might work with distribution nodejs packages, but it seems pretty sketchy.

Update this paste sums up the second link above, but doesn't work for me (it seems like npm ignores ~/.npmrc, at least during install).

标签: node.js npm
7条回答
Fickle 薄情
2楼-- · 2019-01-20 22:01

Because python does already a great job virtualenv, I use nodeenv. Compared to nvm, you can create multiple environments for the same node version (e.g. two environments for node 0.10 but with different sets of packages).

ENVNAME=dev1

#  create an environment
python -m virtualenv ${ENVNAME}

# switch to the newly created env
source ${ENVNAME}/bin/activate

# install nodeenv
pip install nodeenv

# install system's node into virtualenv
nodeenv --node=system --python-virtualenv

The readme is pretty good: https://github.com/ekalinin/nodeenv

查看更多
登录 后发表回答