Install node JS on Mac

Source: Internet
Author: User
Tags install openssl install node

I have never liked to pursue new things and finally took the step one year after node JS came out.

To put it bluntly, configure the environment first. Google "Mac node" has several results. The methods provided are basically the same, so you can start to practice it. Installation Steps after Google attachment:

1. Install xcode and git;

2. Use git to pull the node source code to the local git: // github.com/ry/node.git

3../configure

4. Make

5. Make install

Fortunately, you have installed xcode and git before. Otherwise, you may just download and install xcode. This evening, you will be fully reimbursed (for the poor network experience ). With these two things, the installation should be easy. However, there are several problems, first of all. /configure, there are a few things: OpenSSL-> not found, library-> not found, fdatasync (2) with C ++-> NO. Then, when making, the system reports an error: Build failed:-> task failed (ERR #1 ):....

After that, I repeated it several times, but it was unsuccessful. I began to doubt whether it was caused by OpenSSL or lack of library Rt. I was prepared to install OpenSSL. By the way, I asked in the group, A friend suggested using node 0.6.1, and then ran to GitHub, downloaded the source code of the latest version, repeat the installation steps on Google, 'build' finished successfully, 'install' finished successfully, done! It turns out to be a version issue. Of course, what is the internal issue of the version? Here we will not go into it, but helloworld will come out first.

After the installation is successfulProgramCopy one copy and save it as helloworld. js to the node installation directory,

 
VaRHTTP = require ('http ');
HTTP. createserver (Function(Req, Res ){
Res. writehead (200, {'content-type': 'text/plain '});
Res. End ('Hello world \ n ');
}). Listen (8808, '192. 0.0.1 ');
Console. Log ('server running at http: // 127.0.0.1: 8080 ');

 

Run node helloworld. JS, you can see the "server running at http: // 127.0.0.1: 8808" information in the Command window (console), enter localhost: 8808 in the browser, the page cannot be connected, sadly, what's going on. Go to the console and check that an error is reported:The 'sys 'module is now called' util '. it shoshould have a similar interface. it seems that an interface is to be implemented, but it is not correct. This is the official helloworld, and an error can still be made. Is it swollen? Is it a version issue? Node-V, version is node-v0.6.2 pre, good, 0.6.2 latest version, and I ran 0.6.1 helloworld, error. Since the official website currently provides 0.6.1 documentation, let's take a look at 0.6.1 first.

Okay, there is another reinstallation. I learned this lesson by taking version 0.6.1 from the official website and repeating the above steps. When making install, I encountered an error again. I need to delete the installed version 0.6.2 pre, because it uses the usr/local/include/node directory and the config. h cannot be rewritten. Dear user, you do not have sudo permission. If you do not have permission, sudo obtains the Administrator permission and re-runs sudo make install. The installation is successful.

Continue to run node helloworld. JS, the console is normal, and can access localhost: 8808, OK, and finally get it done. It is also a wave of twists and turns.

Note that if your program hasCodeError: the console prints the console information first, and then reports an error message to you. For example, the 'sys 'module is now called 'util' error in the 0.6.2 pre-report '. it shoshould have a similar interface, for example, you put res. writehead Ctrip Rs. writehead.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.