node. JS Installation and Configuration
node. JS has been in existence for more than two years, and since it's been in rapid development, some of the previous installation configurations have been introduced for most of the 0.4.x versions, and not for the latest 0.6.x versions, we'll cover the installation and configuration of node. JS on the 0.6.x version. (This article takes 0.6.1 as an example, the remaining version of 0.6, just replace the version number.) From http://nodejs.org/#download可以查看到最新的二进制版本和源代码).
- node. JS installation under Windows platform
In the past, node. JS had not supported native compilation under the Windows platform and needed to emulate the POSIX system with Cygwin or MinGW to compile the installation. Fortunately, in June 2011, Microsoft started working with Joyent to migrate node. js to the Windows platform (Http://www.infoq.com/cn/news/2011/06/node-exe), The results of this collaboration were finally presented in the stable release of 0.6.x. This release makes node. js significantly more efficient on Windows platforms, easier and lighter to use, completely free from lab-like environments such as Cygwin or mingw, and shows higher performance than Linux in some details, see HTTP// Www.infoq.com/news/2011/11/Nodejs-Windows. Under the Windows (WINDOWS7) platform, I'll cover two ways to install node. js, the common and artistic installation method.
- Common installation Methods
The common installation method is actually the simplest method, for most Windows users, are not too fond of tossing people, you can from here (http://nodejs.org/dist/v0.6.1/node-v0.6.1.msi Download directly to the node. JS compiled MSI file. Then double-click to complete the installation under the program's boot. Run directly on the command line: The NODE-V command lines will print out: v0.6.1 The boot step installs the Node.exe file into the C:\Program files (x86) \nodejs\ directory and adds the directory to the PATH environment variable.
- The installation method of literature and art
- node. JS installation under the Unix/linux platform
Because node. JS is still in the v0.x.x version of the rapid development, the Unix/linux platform's release will not be pre-set node binary files, compiled through the source code is the best choice for the present. And the students with Unix/linux system are mostly literary programmers, this section only describes how to compile and install through the source code.
Like under the Windows platform, node. JS still manages the build project with the Gyp tool, unlike the final compilation with the Make tool. So under the Unix/linux platform you need the following prerequisites to ensure that the compilation is complete: 1. Python. For Gyp, you can see if Python is installed by executing the python command under the shell, and confirm that the version meets the requirements (2.6 or later, but not 3.0). 2. Source code compilers, usually the Unix/linux platform comes with a C + + compiler (gcc/g++). If not, install make,g++ These compilation tools through the current release of the package installation tool. A. The tool under Debian/ubuntu is Apt-get B. Redhat/centos under the Yum command c. MAC OS x You may need to install Xcode to get compiler-related vendor content Scala, which lets the Java platform programmed to reproduce 3. Second, if you plan to enable network encryption in node. JS, the cryptographic libraries of OpenSSL are also required. The cryptographic library is Libssl-dev and can be installed by commands such as Apt-get install Libssl-dev.
- Check the environment and install
After completing the above prerequisites, we obtain the source code and conduct environmental inspection:
| wget http://nodejs.org/dist/v0. 6.1/node-v0.6.1.tar.gz tar zxvf node-v0.6.1.tar.gz cd node-v0.6.1 ./configure The above command is to download the latest version of the code through the wget command and unzip it: the/configure command will check whether the environment conforms to the NODEJS compilation needs. Checking for program g++ or C + +:/usr/bin/g++ Checking for program CPP:/usr/bin/cpp Checking for program AR :/usr/bin/ar Checking for program Ranlib:/usr/bin/ranlib Checking for g++: ok Checking for program GCC or cc:/usr/bin/gcc Checking for program ar:/usr/bin/ar Checking for program ranlib:/usr/bin/ranlib C Hecking for gcc:ok Checking for library dl:yes Checking for openssl:yes Checking for library util : yes Checking for library rt:yes Checking for Fdatasync (2) with C + +: yes ' Configure ' finished succes Sfully (7.350s)
If the check does not pass, make sure that the three conditions mentioned above are met. If the Configure command executes successfully, it can be compiled:
The Nodejs is compiled and installed with the Make tool (use sudo to ensure that you have permissions if making install is unsuccessful). After completing these two steps, check if the installation is successful: Node-v check to see if it is returned: v0.6.1 to this point, Nodejs has been compiled and installed. If you want to uninstall, you can perform the make uninstall to uninstall.
The full name of NPM is node package Manager, and if you're familiar with Ruby's Gem,python pypl, setuptools,php pear, then you know what NPM is all about. Yes, it's Nodejs's package manager. The Nodejs itself provides the basic modules. However, the development of practical applications on these basic modules requires more work. Fortunately, when I wrote this article, NPM already has 5,112 Nodejs libraries or frameworks that can help nodejs developers with more complex applications in every way. The number and activity of these libraries also reflect the rapid and active development of the Nodejs community. I'll show you how to install NPM and a third-party library that installs Nodejs via NPM, and how to make better use of NPM in a mainland-based network environment.
- Installing NPM under Unix/linux
As the NPM official website (http://npmjs.org/) describes, installing NPM is just one line of command:
|Curl Http://npmjs.org/install.sh | Sh
Here's the meaning of this command, Curl http://npmjs.org/install.sh is to get this installation shell script through the Curl command, press post via pipe break | The obtained script is assigned to the SH command to execute. If the installation is unsuccessful without permissions, you need to add sudo to ensure the permissions:
|Curl Http://npmjs.org/install.sh | sudo sh
After successful installation, the NPM command will be followed by a hint:
|USAGE:NPM <command> where <command> is one of:adduser, Apihelp, author, bin, Bugs, C, cache, completion, con Fig, deprecate, Docs, edit, explore, FAQ, find, GET, help, Help-search, home, I, info, init, install, LA, link, list, LL, ln, LS, outdated, owner, pack, prefix, prune, publish, R, RB, rebuild, remove, restart, RM, Root, Run-script, S, SE, searc H, set, show, Star, start, stop, submodule, tag, test, UN, uninstall, unlink, Unpublish, Unstar, up, update, version, view , WhoAmI
We use underscore as an example to demonstrate the process of installing a third-party package via NPM.
Due to some special network environment, when installing third-party libraries directly through the NPM Install command, the state of the card will often appear. Fortunately, the domestic Cnode community @fire9 students to use their spare time to build a mirrored NPM library, the server is set up in Japan, you can bypass some unnecessary network problems. You can install a third-party library by following this command:
|NPM--registry "http://npm.hacknodejs.com/" Install underscore
If you want to set it as the default repository, run the following command:
|NPM Config Set registry "http://npm.hacknodejs.com/"
After Setup, you can not take the-registry parameter on each installation. It is worth mentioning that there is another mirror available, the mirror address is http://registry.npmjs.vitecho.com, if you want to use, replace the address of the above two lines of command.
- Installing NPM under Windows
Because of the historical reasons for Nodejs's initial Linux development, NPM did not initially support the Windows environment, but as Nodejs successfully ported to the Windows platform, NPM's requirements for windows were growing. Let's start the NPM tour under Windows.
Since the GitHub website does not support direct download of all submodule packages, it is necessary to check out all the source code through the Git tool. From Http://code.google.com/p/msysgit/downloads/list, you can download to msysgit the GIT client tool under this Windows platform. After the download, double-click Install.
Locate the bin location in the git installation path, such as: C:\Program files\git\bin \ To find the location of Git-core in the GIT installation path, such as C:\Program files\git\libexec\git-core\; C:\Program files\git\ "is the installation path and may not be the same as your installation path, replace the" C:\Program files\git\ "with your own path. Right-click Computer, properties, advanced system settings, environment variables, locate path in the system variables below, select Path, and choose Edit-- Copy the found bin and git-core paths to them, save and exit, "path", and enter the semicolon in the English state between each path ";" As an interval.
Open the command-line tool (CMD) and execute the following command to check out all of NPM's source and dependency code and install NPM with Msysgit.
|git clone--recursive git://github.com/isaacs/npm.git CD NPM node cli.js install NPM-GF
Before executing this code, make sure that the Node.exe is installed in the way that is node.msi, or in the PATH environment variable. This command also adds NPM to the PATH environment variable and can then execute the NPM command anywhere. If you encounter permissions errors in your installation, make sure that the CMD command-line tool is running as an administrator. After the installation is successful, execute the following command:
This is done with NPM installed under the Windows platform. If you encounter network problems that cannot be installed, refer to the NPM command under Linux to add a mirrored address.