我正在尽可能多地使用Homebrew。在MacOS X上安装Node.js、nvm和npm的推荐方式是什么?
当前回答
Using homebrew install nvm: brew update brew install nvm source $(brew --prefix nvm)/nvm.sh Add the last command to the .profile, .bashrc or .zshrc file to not run it again on every terminal start. So for example to add it to the .profile run: echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.profile If you have trouble with installing nvm using brew you can install it manually (see here) Using nvm install node or iojs (you can install any version you want): nvm install 0.10 # or nvm install iojs-1.2.0 npm is shipping with node (or iojs), so it will be available after installing node (or iojs). You may want to upgrade it to the latest version: $ npm install -g npm@latest UPD Previous version was npm update -g npm. Thanks to @Metallica for pointing to the correct way (look at the comment bellow). Using npm install ionic: npm install -g ionic What about ngCordova: you can install it using npm or bower. I don't know what variant is more fit for you, it depends on the package manager you want to use for the client side. So I'll describe them both: Using npm: Go to your project folder and install ng-cordova in it: npm install --save ng-cordova Using bower: Install bower: npm install -g bower And then go to your project folder and install ngCordova in it: bower install --save ngCordova
PS
某些命令可能需要超级用户权限 npm install some_module的简写是npm i some_module
其他回答
Using homebrew install nvm: brew update brew install nvm source $(brew --prefix nvm)/nvm.sh Add the last command to the .profile, .bashrc or .zshrc file to not run it again on every terminal start. So for example to add it to the .profile run: echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.profile If you have trouble with installing nvm using brew you can install it manually (see here) Using nvm install node or iojs (you can install any version you want): nvm install 0.10 # or nvm install iojs-1.2.0 npm is shipping with node (or iojs), so it will be available after installing node (or iojs). You may want to upgrade it to the latest version: $ npm install -g npm@latest UPD Previous version was npm update -g npm. Thanks to @Metallica for pointing to the correct way (look at the comment bellow). Using npm install ionic: npm install -g ionic What about ngCordova: you can install it using npm or bower. I don't know what variant is more fit for you, it depends on the package manager you want to use for the client side. So I'll describe them both: Using npm: Go to your project folder and install ng-cordova in it: npm install --save ng-cordova Using bower: Install bower: npm install -g bower And then go to your project folder and install ngCordova in it: bower install --save ngCordova
PS
某些命令可能需要超级用户权限 npm install some_module的简写是npm i some_module
我同意noa——如果你需要拥有多个版本的node, io.js,那么brew不是合适的解决方案。
你可以在nvm中帮助beta测试io.js支持:https://github.com/creationix/nvm/pull/616
如果你只想要io.js,并且不切换版本,那么你可以从https://iojs.org/dist/v1.0.2/iojs-v1.0.2-darwin-x64.tar.gz安装io.js的二进制发行版;这包括NPM,如果你不切换版本,你将不需要NVM。
记得在安装后更新npm: sudo npm install -g npm@latest
2021年更新
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
MAC故障处理:
从macOS 10.15开始,默认shell是zsh, nvm将寻找.zshrc来更新,默认情况下没有安装。用touch ~/创建一个。ZSHRC并再次运行安装脚本。
如果您使用bash(前面的默认shell),则运行touch ~/。Bash_profile来创建必要的配置文件(如果不存在)。
您可能需要重新启动终端实例或运行。~ / .nvm / nvm.sh。重新启动终端/打开新选项卡/窗口,或运行source命令将加载该命令和新配置。
您以前使用过bash,但是安装了zsh。您需要手动将这些行添加到~/。ZSHRC并运行。~ / . zshrc。
使用zsh和Homebrew安装:
brew install nvm <=== This is not recommended by NVM. They want to run their shell script instead
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
然后将以下内容添加到~/。ZSHRC或您所需的shell 配置文件:
export NVM_DIR="$HOME/.nvm"
. "/usr/local/opt/nvm/nvm.sh"
然后安装一个节点版本并使用它。
nvm install 7.10.1
nvm use 7.10.1
使用nvm安装Node.js,而不是Homebrew
在大多数回答中,推荐使用Homebrew安装nvm。
不要这样做。
在nvm的Github上,Readme清楚地说:
不支持自制程序安装。如果你对homebrew安装的nvm有问题,请先卸载它,然后按照下面的说明进行安装,然后再提交问题。
请使用下面的方法
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
脚本将nvm存储库克隆到~/。NVM并将源行添加到概要文件(~/。bash_profile、~ /。zshrc ~ /。或者~/.bashrc)。
然后使用nvm安装node。例如,要安装最新的LTS版本,请:
nvm install 16
干净,没有麻烦。它会把这个设置为你的默认Node.js版本,所以你应该都设置好了。
推荐文章
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- ReferenceError: description没有定义NodeJs
- “你有邮件”的消息在终端,os X
- 将一个二进制的NodeJS Buffer转换为JavaScript的ArrayBuffer
- Mac OS X中的环境变量
- AngularJS只适用于单页应用程序吗?
- 如何在vue-cli项目中更改端口号
- Homebrew:以新的formula@version格式列出可用版本
- 如何从macOS完全卸载蟒蛇
- 如何查看npm包的大小?
- 同步和异步编程(在node.js中)的区别是什么?
- 如何编辑通过npm安装的节点模块?
- 如何配置Mac OS X术语,使git有颜色?
- “node_modules”文件夹应该包含在git存储库中吗