如何安裝Node.js

來源:互聯網
上載者:User

原文地址:http://www.ooso.net/archives/589

參考地址:http://cnodejs.org/blog/?p=2080

下面分別介紹在Mac, Ubuntu,Centos以及Windows下安裝Node.js.

Mac

在Mac下,如果你喜歡用homebrew,那麼只用一行就可以裝好:

brew install node

否則,只能考慮手工安裝了,步驟如下:

    1. 安裝Xcode
    2. 安裝git
    3. 運行下面的命令列編譯node.js
      git clone git://github.com/joyent/node.git
      cd node
      ./configure
      make
      sudo make install
    Ubuntu
      1. 安裝依賴包

        sudo apt-get install g++ curl libssl-dev apache2-utils
        sudo apt-get install git-core
      2. 運行下面的命令列:
        git clone git://github.com/joyent/node.git
        cd node
        ./configure
        make
        sudo make install
      Windows

      用cygwin來安裝node,步驟如下:

        1. 安裝cygwin
        2. 在cygwin的目錄下,運行setup.exe安裝下面列表中的包
          • devel → openssl
          • devel → g++-gcc
          • devel → make
          • python → python
          • devel → git
        3. 運行cygwin
        4. 運行下面的命令列:
          git clone git://github.com/joyent/node.git
          cd node
          ./configure
          make
          sudo make install
        Centos
        yum install gcc-c++ openssl-devel
        wget --no-check-certificate https://github.com/joyent/node/tarball/v0.3.3
        tar -xzvf ry-node-v0.3.3-0-g57544ba.tar.gz
        cd ry-node-v0.3.3-0-g57544bac1
        ./configure
        make
        make install
        Hello Node.js!

        寫一段小程式例如hello_node.js來驗證安裝是否正確:

        var http = require('http');
        http.createServer(function (req, res) {
          res.writeHead(200, {'Content-Type': 'text/plain'});
          res.end('Hello Node.jsn');
        }).listen(8124, "127.0.0.1");
        console.log('Server running at http://127.0.0.1:8124/');

        用node來運行這段代碼

        node hello_node.js
        Server running at http://127.0.0.1:8124/

        現在,用瀏覽器開啟 http://127.0.0.1:8124/ , 應該能夠看到一條好訊息。

        聯繫我們

        該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

        如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

        A Free Trial That Lets You Build Big!

        Start building with 50+ products and up to 12 months usage for Elastic Compute Service

        • Sales Support

          1 on 1 presale consultation

        • After-Sales Support

          24/7 Technical Support 6 Free Tickets per Quarter Faster Response

        • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.