一、node运行环境
1、npm install -g n
通过npm 全局安装node
2、sudo n 8.16.0
设置node版本
Password:
install : node-v8.16.0
mkdir : /usr/local/n/versions/node/8.16.0
fetch : https://nodejs.org/dist/v8.16.0/node-v8.16.0-darwin-x64.tar.gz
######################################################################## 100.0%
installed : v8.16.0
3、node -v
v8.16.0
二、安装mongodb
1、brew tap mongodb/brew
2、brew install mongodb-community
=> Installing mongodb-community from mongodb/brew ==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.5.tgz ######################################################################## 100.0% ==> Caveats To have launchd start mongodb/brew/mongodb-community now and restart at login: brew services start mongodb/brew/mongodb-community Or, if you don't want/need a background service you can just run: mongod --config /usr/local/etc/mongod.conf ==> Summary 🍺 /usr/local/Cellar/mongodb-community/4.2.5: 21 files, 305.9MB, built in 7 minutes 4 seconds (base) mengfaniaodeMBP:homebrew-core mengfanxiao$ cat usr/local/etc/mongod.conf cat: usr/local/etc/mongod.conf: No such file or directory (base) mengfaniaodeMBP:homebrew-core mengfanxiao$ brew services start mongodb/brew/mongodb-community ==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
3、启动/停止
brew services start mongodb-community
brew services stop mongodb-community
4、配置
配置文件:/usr/local/etc/mongod.conf
日志目录路径:/usr/local/var/log/mongodb
数据目录路径:/usr/local/var/mongodb
5、端口
默认端口 |
介绍 |
27017 |
mongod 和 mongos 实例的默认端口。你可以通过 port 或 --port 改变该端口。 |
27018 |
设置 --shardsvr 运行变量或在配置文件里设置 clusterRole 为 shardsvr 时的默认端口。 |
27019 |
设置 --configsvr 运行变量或在配置文件中将 clusterRole 设置为 configsvr 时的默认端口。 |
28017 |
系统状态网页的默认端口。系统状态网络页面永远可以在比 port 大 1000 的端口反问。 |
三、问题梳理
1、环境问题
node -v
dyld: Library not loaded:
/usr/local/opt/icu4c/lib/libicui18n.64.dylib
Referenced from: /usr/local/bin/node
Reason: image not found
Abort trap: 6
说明node相关库已被损坏 需要重新安装
卸载node
brew uninstall --ignore-dependencies node icu4c
Uninstalling /usr/local/Cellar/node/13.5.0... (4,663 files, 59.1MB)
node 12.12.0 is still installed.
Run `brew uninstall --force node` to remove all versions.
安装node
brew install node
通过这种方式安装的是最新版本的node 但很容易出现版本不兼容问题 所以不推荐这么安装 建议安装node8 该版本比较稳定 很少出现与其他软件不兼容情况
2、文件创建权限问题
==> Installing dependencies for node: icu4c ==> Installing node dependency: icu4c ==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/bottles/icu4c-64.2.mojave.bottle.tar.gz ######################################################################## 100.0% ==> Pouring icu4c-64.2.mojave.bottle.tar.gz Error: Failed to create /usr/local/opt/icu4c Things that depend on icu4c will probably not build. Could not symlink . /usr/local/opt is not writable. ==> Caveats
a、创建文件夹
sudo mkdir /usr/local/opt
b、root用户赋予当前用户操作该文件夹权限
此时该文件夹权限属于root 给mengfanxiao账户赋予权限
chown -R mengfanxiao /usr/local/opt
3、插曲 springboot启动问题
dea启动spring-boot,报java.lang.NoClassDefFoundError: javax/servlet/ServletContext错误
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
把scope注释掉即可
maven中三种classpath
编译,测试,运行
1.compile:默认范围,编译测试运行都有效
2.provided:在编译和测试时有效
3.runtime:在测试和运行时有效
4.test:只在测试时有效
5.system:在编译和测试时有效,与本机系统关联,可移植性差
4、环境不匹配问题
Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (79)qi
卸载重装(最新版本的node-sass)即可:
npm uninstall node-sass -D
npm install node-sass -D
5、版本冲突问题 node和mongodb版本不兼容
mongodb-core@1.2.31 requires a peer of kerberos@~0.0
node -v v13.12.0
npm -v 6.14.4
gyp ERR! command "/usr/local/Cellar/node/13.12.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /Users/mengfanxiao/Documents/project/company/wechain/questionnaire/node_modules/leveldown
gyp ERR! node -v v13.12.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN mongodb-core@1.2.31 requires a peer of kerberos@~0.0 but none is installed. You must install peer dependencies yourself.
这种情况需要安装node8
brew search node
==> Formulae
libbitcoin-node node node-sass node@12 nodebrew nodenv
llnode node-build node@10 node_exporter ✔ nodeenv
如果有node8
则 brew install node@8
然后brew link --overwrite --force node@8
没有node8
npm install -g n
sudo n 8.16.0
安装了node8版本
npm install
> leveldown@1.7.2 install /Users/mengfanxiao/Documents/project/company/wechain/new/questionnaire/node_modules/level/node_modules/leveldown
> prebuild-install || node-gyp rebuild
added 42 packages from 44 contributors in 20.79s
6、安装mongodb问题
brew install mongodb
Error: No available formula with the name 'mongodb'
MongoDB不再是开源的了,并且已经从Homebrew中移除 #43770
安装MongoDB社区服务器的最新可用生产版本(包括所有命令行工具)。这将安装MongoDB 4.2.x:
$ brew install mongodb-community
安装MongoDB社区服务器和命令行工具的最新4.2.x生产版本:
$ brew install mongodb-community@4.2
安装MongoDB社区服务器和命令行工具的最新4.0.x生产版本:
$ brew install mongodb-community@4.0
安装MongoDB社区服务器和命令行工具的最新3.6.x生产版本:
$ brew install mongodb-community@3.6
仅安装最新的mongoshell以连接到远程MongoDB实例:
$ brew install mongodb-community-shell