homebrew是mac平台常用的包管理工具,本文将先说明homebrew使用过程中的常见问题,接着以mongodb的安装过程演示如何使用homebrew安装软件。
常见问题
查看homebrew帮助命令
使用命令$ brew help
查看mac上全部已安装应用
使用命令$ brew list
查看mac上全部使用homebrew安装的应用:
gdbm mongodb pkg-config qt redis
git openssl python readline sqlite
查看某个应用包含的全部组件
使用命令$ brew list xxx
,对应redis就是$ brew list redis
,输出
/usr/local/Cellar/redis/3.2.3/bin/redis-benchmark
/usr/local/Cellar/redis/3.2.3/bin/redis-check-aof
/usr/local/Cellar/redis/3.2.3/bin/redis-check-rdb
/usr/local/Cellar/redis/3.2.3/bin/redis-cli
/usr/local/Cellar/redis/3.2.3/bin/redis-sentinel
/usr/local/Cellar/redis/3.2.3/bin/redis-server
/usr/local/Cellar/redis/3.2.3/homebrew.mxcl.redis.plist
查看某个应用信息
使用命令$ brew info redis
,输出
redis: stable 3.2.3, HEAD
Persistent key-value database, with built-in net interface
http://redis.io/
/usr/local/Cellar/redis/3.2.3 (10 files, 1.7M) *
Built from source on 2017-03-27 at 20:11:31
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/redis.rb
==> Options
--with-jemalloc
Select jemalloc as memory allocator when building Redis
--HEAD
Install HEAD version
==> Caveats
To have launchd start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf
安装位置
一般使用homebrew安装的软件都位于/usr/local/Cellar/
路径下,同时会在/usr/local/bin/
下建立一个指向/usr/local/Cellar/
下软件实际位置的一个符号链接.因为/usr/local/bin
被加入了PATH环境变量,因此使用homebrew安装的应用不需要专门去设置PATH环境变量,参考我的另一篇文章Homebrew安装Packages是否需要另外设置环境变量PATH.
配置文件位置
如果安装的应用需要配置文件,一般会在/usr/local/etc
下为该应用建立默认的配置文件.使用命令$ ls /usr/local/etc
查看目前为止的配置文件:
bash_completion.d mongod.conf redis-sentinel.conf
dump.rdb openssl redis.conf
可以看到有mongodb数据库以及redis等的配置文件.
数据存储位置
homebrew安装的应用产生的数据一般存储在/usr/local/var
下面.
安装mongodb
首先使用命令$ brew search mongodb
搜索可以安装的版本:
==> Searching local taps...
mongodb mongodb@3.2 mongodb@3.6
mongodb@3.0 mongodb@3.4 percona-server-mongodb
==> Searching taps on GitHub...
homebrew/cask-versions/mongodb-compass-beta
homebrew/cask/mongodb
homebrew/cask/mongodb-compass
homebrew/cask/mongodb-compass-community
homebrew/cask/mongodb-compass-readonly
homebrew/cask/orelord-mongodb
==> Searching blacklisted, migrated and deleted formulae...
接下来安装搜索到的mongodb@3.6版本,执行安装命令$ brew install mongodb@3.6
:
Updating Homebrew...
==> Installing dependencies for mongodb@3.6: gdbm, openssl, readline, sqlite, python@2
.......
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/mongodb@3.6/bin:$PATH"' >> ~/.bash_profile
To have launchd start mongodb@3.6 now and restart at login:
brew services start mongodb@3.6
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@3.6/3.6.5: 19 files, 298.0MB
网友评论