zoukankan      html  css  js  c++  java
  • mac 下安装node.js

    参考http://www.ooso.net/archives/589

    开始的时候是各种方法都尝试了一遍,最后还是选择了最简单的homebrew的方法

    虽然是最简单的,但是在安装的过成功中也出现了各种问题

    下载后将文件解压缩放在了桌面上

    打开终端进入目录执行

    cd /users/macpro/desktop

    cd homebrew-master/bin

    brew install node

    开始执行后出现提示:xcode版本太低,让我升级,花了几个小时下载了1G多的xcode升级成功 

    同时安装了Command line tools 去苹果developer.apple找就可以

    后又提示我已经安装了npm(因为之前尝试的安装方法太多,什么都安装了)

    两个选择

    要么删除后使用homebrew的  npm uninstall npm -g

    要么使用自己默认的  brew install node --without-npm

    第一次使用了第二个方法,但是最终没能成功

    后尝试第一种方法 发了狠 把相关目录下所有的文件全部删除 重新开始

    上面三段代码执行完毕之后又提示我连接没有成功The `brew link` step did not complete successfully

    于是终端上brew link node重新简历连接

    结果提示

    Error: Could not symlink file: /usr/local/Cellar/node/0.10.0/bin/node
    Target /usr/local/bin/node already exists. You may need to delete it.
    To force the link and delete this file, do:
    brew link --overwrite formula_name

    To list all files that would be deleted:
    brew link --overwrite --dry-run formula_name

    使用第二个方法brew link --overwrite --dry-run node

    根据提示

    Would remove:
    /usr/local/bin/node

    删除文件

    用brew link node重新链接终于完满(如果是第一次安装的人大概没这么复杂)

     npm -v
    1.2.14
     node -v
    v0.10.0

    检测版本完毕

    然后进行测试

    由于我是第一次接触node.js

    甚至是从来没有过js的基础所以完全不知道代码应该在哪里写

    后来才知道 哪怕是文本编辑的.js的文件都可以运行

    安装的默认文件路径就是homebrew-master/bin/

    但是当时不知道

    所以随便执行了一个文件

    当然提示错误Cannot find module '/Users/macpro/Desktop/homebrew-master/bin/hello_node.js'

    于是我理所当然找到了文件的默认路径(偷笑 此方法实在是侥幸)

    将事先准备好的.js文件放到这个目录下 重新执行node nodetest001.js

    nodetest001.js代码如下(几乎网上所有的教程都是这段代码)

    var http = require('http');

    http.createServer(function (request, response) {

      response.writeHead(200, {'Content-Type': 'text/plain'});

      response.end('Hello World\n');

    }).listen(8124);

     console.log('Server running at http://127.0.0.1:8124/');

    执行后终端输出

    Server running at http://127.0.0.1:8124/

    使用浏览器访问http://127.0.0.1:8124/

    页面上显示一行所有程序员逃不了的劫:

    Hello World!

  • 相关阅读:
    Linux-KVM, QEMU, Virtualbox, VMWare
    Linux环境下查看CPU是否支持VT虚拟化
    (OK) Phoronix Test Suite
    GNS3: Qemu or VirtualBox?
    Android x86 On Qemu
    ARC Welder——Android 模拟器——App Runtime for Chrome
    Running Android apps using Docker and ARC Welder
    使用Docker编译Android(AOSP)
    Android —— releases of AOSP
    (OK) install android-x86-5.1 on virtualbox
  • 原文地址:https://www.cnblogs.com/PhenixWang/p/2961535.html
Copyright © 2011-2022 走看看