win7 + cygwin + nodejs很详细的安装步骤

本文提供了一套详细的Win7环境下安装Node.js的步骤,包括使用cygwin进行安装,解决安装过程中可能出现的问题,以及如何通过cygwin安装所需的软件包。此外,文章还介绍了如何设置DNS,并提供了Node.js的测试方法,包括测试HTTP服务器和使用npm进行软件包管理。

win7下安装node.js详细步骤

1.下载cygwin:http://cygwin.com/setup.exe
2.安装cygwin几个要点:

(1)Install from Internet,安装程序在后面步骤会下载大量文件。
(2)Root Directory,是Cygwin的安装目录。
(3)Local Package Directory,是存放所有下载文件的目录,子目录名即下载镜像网址,子目录下的release目录存放的就是所下载的包。
(4)选择连接方式:可以直接连接(Direct Connection),也可以使用代理(Proxy)。
(5)下载镜像站点推荐:
http://mirrors.kernel.org
http://cygwinminor.3gforphones.com
http://mirrors.163.com/cygwin
http://mirrors.sohu.com/cygwin/
也可以获得官方镜像列表后自己验证,http://cygwin.com/mirrors.lst

(6)首次安装提示信息,OK忽略,但如果安装过cygwin 1.7以下版本,参考:
http://cygwin.com/cygwin-ug-net/ov-new1.7.html

(7)选择包。Default所选包的缺省安装项,Install所选包的全部项,Reinstall断点续传,Uninstall卸载。推荐Install方式。
nodejs所需包:

Devel(开发)目录下的包:
gcc-g++: C++ compiler
gcc-mingw-g++: Mingw32 support headers and libraries for GCC C++
gcc4-g++: G++ subpackage
git: Fast Version Control System – core files(它可以从 github 下载软件最新版源码)
make: The GNU version of the 'make' utility
openssl-devel: The OpenSSL development environment
pkg-config: A utility used to retrieve information about installed libraries
zlib-devel: The zlib compression/decompression library (development)

Editor目录下的包:
vim: Vi IMproved - enhanced vi editor

Python目录下的包:全部Install方式安装

Web目录下的包:
wget: Utility to retrieve files from the WWW via HTTP and FTP
curl: Multi-protocol file transfer command-line tool,npm(node's package manager),nodejs软件包管理器,通过它安装Nodejs各种扩展模块

选完包,Next,如果所选软件包有依赖包,Next确认。

(8)一般情况下,下载所需时间真的很久。下载进度如果出现停滞,取消后重启setup.exe,所有设置同前一次,一直Next到选包部分,Reinstall,已下载过的包会做md5校验码检测,完整下载过的不会再次下载。下载完后进入自动安装,Cygwin安装目录下的bin、lib、usr这3个目录的内容会迅速增长。
3.Windows 7(windows Vista) 特殊步骤

Windows 7(Windows Vista及以后版本),要正常编译nodejs,必须先在Cywgin的ASH模式下执行rebaseall。步骤如下:
(1)cmd命令行
(2)进入cygwin安装目录下的bin子目录
(3)运行ash进入shell模式
(4)./rebaseall -v
(5)没有错误,完成,exit退出ash,关闭命令行窗口
4.rebaseall时出现错误的解决方案:

(1)rebaseall:'/cygdrive/c/Users/ADMINI~1/AppData/Local/Temp' is not writable
启动cygwin安装目录下的cygwin.bat进入终端后:
$cd /
$chmod 777 cygdrive/c/Users/ADMINI~1/AppData/Local/Temp
关闭退出终端

(2)FixImage (/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_sjlj-1.dll) faile, with last error = 13
修改cygwin安装目录下bin子目录下的rebaseall文件,110行增加下列代码:
-e '/\/sys-root\/mingw\/bin/d'
修改后的110行如下:
sed -e '/\/sys-root\/mingw\/bin/d' -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' -e 's/^/\//' >"$TmpFile"
修改后保存,重新./rebaseall -v
5.cygwin终端中下载、编译、安装nodejs

$ wget http://nodejs.org/dist/node-v0.4.8.tar.gz
$ tar xf node-v0.4.8.tar.gz
$ cd node-v0.4.8
$ ./configure
$ make
$ make install

 

6.设置DNS

cygwin内部是使用windows的DNS查询,而nodejs另外使用的是c-ares库来解析DNS,这个库会读取/etc/resolv.conf里的nameserver配置,而默认是没有这个文件的,需要自己建立并配置好DNS服务器的IP地址,这里使用Google Public DNS服务器的IP地址:8.8.8.8和8.8.4.4。

$ vi /ect/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4


7.nodejs测试

(1)查看nodejs的版本信息:
$node -v

(2)编写一个简单的js文件测试nodejs的Http Server,我这里的存放路径为cygwin安装目录下里的home/Administrator/node-v0.4.8/test.js,UTF-8编码保存js文件。代码用记事本编写的,内容如下:

var http = require('http'),port = 8888;

http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'text/html;charset=utf-8;'});
response.end('<h1>这里是NodeJS的世界!</h1>');
}).listen(port);

console.log('服务已启动 );

(3)测试
$ cd node-v0.4.8
$ node test.js
服务已启动 http://127.0.0.1:8888/

A.浏览器打开http://127.0.0.1:8888/,输出页面内容:这里是NodeJS的世界!
B.curl
$ curl http://127.0.0.1:8888/
<h1>这里是NodeJS的世界!</h1>

test.js如有更改,CTRL+C停止Http Server,然后重新开启,$ node test.js
8.npm下载、安装、使用
npm是nodejs的软件包管理器,可以用它安装所需软件包并发布自己为nodejs写的软件包,它还管理软件包的依赖关系并做了其它一些很酷的事情。

(1)一行命令下载并安装npm
$ curl http://npmjs.org/install.sh | sh

(2)npm安装node扩展包,同样是一行命令下载并安装好软件包
$ npm install <包名>

 

 

0 verbose cli D:\software\nvm\nodejs\node.exe D:\software\nvm\nodejs\node_modules\npm\bin\npm-cli.js 1 info using npm@11.6.2 2 info using node@v24.11.1 3 silly config load:file:C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\npmrc 4 silly config load:file:C:\Users\lizhe\.npmrc 5 silly config load:file:D:\software\nvm\nodejs\etc\npmrc 6 verbose title npm install cline 7 verbose argv "install" "--global" "cline" 8 verbose logfile logs-max:10 dir:C:\Users\lizhe\AppData\Local\npm-cache\_logs\2025-12-12T04_43_20_714Z- 9 verbose logfile C:\Users\lizhe\AppData\Local\npm-cache\_logs\2025-12-12T04_43_20_714Z-debug-0.log 10 silly packumentCache heap:4496293888 maxSize:1124073472 maxEntrySize:562036736 11 silly logfile start cleaning logs, removing 1 files 12 silly logfile done cleaning log files 13 silly idealTree buildDeps 14 silly fetch manifest cline@* 15 silly packumentCache full:https://registry.npmmirror.com/cline cache-miss 16 http fetch GET 200 https://registry.npmmirror.com/cline 305ms (cache revalidated) 17 silly packumentCache full:https://registry.npmmirror.com/cline set size:92641 disposed:false 18 silly placeDep ROOT cline@1.0.8 OK for: want: * 19 verbose stack Error: Unsupported platform 19 verbose stack at checkPlatform (C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\node_modules\npm-install-checks\lib\index.js:42:25) 19 verbose stack at #checkEngineAndPlatform (C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:215:9) 19 verbose stack at Arborist.buildIdealTree (C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:185:41) 19 verbose stack at async Arborist.reify (C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:114:5) 19 verbose stack at async Install.exec (C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\lib\commands\install.js:150:5) 19 verbose stack at async Npm.exec (C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\lib\npm.js:208:9) 19 verbose stack at async module.exports (C:\Users\lizhe\AppData\Local\nvm\v24.11.1\node_modules\npm\lib\cli\entry.js:67:5) 20 verbose pkgid cline@1.0.8 21 error code EBADPLATFORM 22 error notsup Unsupported platform for cline@1.0.8: wanted {"os":"darwin,linux","cpu":"x64,arm64"} (current: {"os":"win32","cpu":"x64"}) 23 error notsup Valid os: darwin,linux 23 error notsup Actual os: win32 23 error notsup Valid cpu: x64,arm64 23 error notsup Actual cpu: x64 24 silly unfinished npm timer reify 1765514600933 25 silly unfinished npm timer reify:loadTrees 1765514600936 26 verbose cwd D:\JavaFile\aipic 27 verbose os Windows_NT 10.0.26200 28 verbose node v24.11.1 29 verbose npm v11.6.2 30 verbose exit 1 31 verbose code 1 32 error A complete log of this run can be found in: C:\Users\lizhe\AppData\Local\npm-cache\_logs\2025-12-12T04_43_20_714Z-debug-0.log
最新发布
12-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值