MacOS使用brew安裝mongodb

1、使用brew安裝mongodb需要先更新brew
brew update

如果更新時抱如下錯誤:

yindengxu@xuyindengdeMacBook-Pro ~ % brew update
Error: 
  homebrew-core is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!

根據(jù)提示執(zhí)行如下命令:

git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

運行結果如下圖所示:

yindengxu@xuyindengdeMacBook-Pro ~ % git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
remote: Enumerating objects: 566713, done.
remote: Counting objects: 100% (566670/566670), done.
remote: Compressing objects: 100% (200947/200947), done.
remote: Total 557950 (delta 359549), reused 552551 (delta 354154), pack-reused 0
接收對象中: 100% (557950/557950), 220.04 MiB | 3.83 MiB/s, 完成.
處理 delta 中: 100% (359549/359549), 完成 3868 個本地對象.
yindengxu@xuyindengdeMacBook-Pro ~ % brew update                                                                     
Updated 1 tap (homebrew/cask).
==> Updated Casks
purevpn
2脚粟、mongodb最新的安裝方法汉矿,之前舊的方法都無效了
brew tap mongodb/brew

運行結果如下:

yindengxu@xuyindengdeMacBook-Pro ~ % brew tap mongodb/brew                                                           
Updating Homebrew...
3、執(zhí)行如下命令:
brew install mongodb-community

運行結果如下圖所示:

yindengxu@xuyindengdeMacBook-Pro ~ % brew install mongodb-community                 
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> Updated Casks
Updated 2 casks.

==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/tools/db/mongodb-database-tools-macos-x86_64-100.2.1.zip
Already downloaded: /Users/yindengxu/Library/Caches/Homebrew/downloads/6e0a5e5b34d438cd760de60976f4aeedb1a9332b2d384323bd68070898d49c47--mongodb-database-tools-macos-x86_64-100.2.1.zip
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.1.tgz
Already downloaded: /Users/yindengxu/Library/Caches/Homebrew/downloads/d46781539dca95a7ced7d9b466b13bd4cc0202f17a8bf4bd499a5e1a4a241262--mongodb-macos-x86_64-4.4.1.tgz
==> Installing dependencies for mongodb/brew/mongodb-community: mongodb-database-tools
==> Installing mongodb/brew/mongodb-community dependency: mongodb-database-tools
??  /usr/local/Cellar/mongodb-database-tools/100.2.1: 13 files, 173MB, built in 6 seconds
==> Installing mongodb/brew/mongodb-community
==> 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.4.1: 11 files, 136.8MB, built in 4 seconds
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/yindengxu/Library/Caches/Homebrew/aom--2.0.0.catalina.bottle.1.tar.gz... (5.5MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/automake--1.16.2_1.catalina.bottle.tar.gz... (949.8KB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/dart--2.10.2.zip... (157.8MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/git--2.28.0.catalina.bottle.tar.gz... (19.4MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/gmp--6.2.0.catalina.bottle.tar.gz... (1022.7KB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/libass--0.14.0_1.catalina.bottle.1.tar.gz... (208.8KB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/libtiff--4.1.0.catalina.bottle.tar.gz... (1.1MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/node--14.14.0.catalina.bottle.tar.gz... (16.8MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/pcre2--10.35.catalina.bottle.tar.gz... (2.0MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/sdl2--2.0.12_1.catalina.bottle.tar.gz... (1.3MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/sqlite--3.33.0.catalina.bottle.tar.gz... (1.9MB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/utf8proc--2.5.0.catalina.bottle.tar.gz... (152.7KB)
Removing: /Users/yindengxu/Library/Caches/Homebrew/x264--r3011.catalina.bottle.1.tar.gz... (2.3MB)
Removing: /Users/yindengxu/Library/Logs/Homebrew/dart... (115B)
Removing: /Users/yindengxu/Library/Logs/Homebrew/node... (64B)
Pruned 0 symbolic links and 1 directories from /usr/local
==> Caveats
==> mongodb-community
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

如果出現(xiàn)下面所示錯誤:

yindengxu@xuyindengdeMacBook-Pro ~ % brew install mongodb-community                                                  
Updating Homebrew...
==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/tools/db/mongodb-database-tools-macos-x86_64-100.2.1.zip
Already downloaded: /Users/yindengxu/Library/Caches/Homebrew/downloads/6e0a5e5b34d438cd760de60976f4aeedb1a9332b2d384323bd68070898d49c47--mongodb-database-tools-macos-x86_64-100.2.1.zip
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.1.tgz
Already downloaded: /Users/yindengxu/Library/Caches/Homebrew/downloads/d46781539dca95a7ced7d9b466b13bd4cc0202f17a8bf4bd499a5e1a4a241262--mongodb-macos-x86_64-4.4.1.tgz
==> Installing dependencies for mongodb/brew/mongodb-community: mongodb-database-tools
==> Installing mongodb/brew/mongodb-community dependency: mongodb-database-tools
Error: Your CLT does not support macOS 11.
It is either outdated or was modified.
Please update your CLT or delete it if no updates are available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you an update run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/more/.

Error: An exception occurred within a child process:
  SystemExit: exit

根據(jù)提示執(zhí)行如下命令:

softwareupdate --all --install --force

運行結果如下:

yindengxu@xuyindengdeMacBook-Pro ~ % softwareupdate --all --install --force
Software Update Tool

Finding available software
No updates are available.

繼續(xù)執(zhí)行如下命令:

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

需要輸入密碼,彈出安裝插件框煤傍,確定安裝战得,運行結果如下:

yindengxu@xuyindengdeMacBook-Pro ~ % sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install
Password:
xcode-select: note: install requested for command line developer tools

4、安裝之后,需要創(chuàng)建一個/data/db文件夾用來作為默認數(shù)據(jù)庫目錄怀估。執(zhí)行以下步驟:
sudo mkdir -p /data/db

因為Mac電腦默認是開啟安全模式的,不能在根目錄下面隨便創(chuàng)建刪除文件夾。所以我們創(chuàng)建的時候多搀,會報這個錯誤mkdir: /data/db: Read-only file system歧蕉,如下:

yindengxu@xuyindengdeMacBook-Pro ~ % sudo mkdir -p /data/db
mkdir: /data/db: Read-only file system

更改為在用戶更目錄下創(chuàng)建數(shù)據(jù)庫默認目錄

mkdir ~/data 

進入剛剛創(chuàng)建的目錄:

cd ~/data

查看目錄路徑,下面會用到:

pwd

運行結果:

/Users/yindengxu/data

指定MongoDB數(shù)據(jù)庫路徑,這里的路徑需要換成你自己電腦上面的路徑

sudo mongod --dbpath=/Users/yindengxu/data

5康铭、執(zhí)行如下命令:

sudo chown ‘username’ /data/db

6惯退、mongodb啟動和停止

brew services start mongodb-community
brew services stop mongodb-community
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市从藤,隨后出現(xiàn)的幾起案子催跪,更是在濱河造成了極大的恐慌,老刑警劉巖夷野,帶你破解...
    沈念sama閱讀 222,807評論 6 518
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件懊蒸,死亡現(xiàn)場離奇詭異,居然都是意外死亡悯搔,警方通過查閱死者的電腦和手機骑丸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,284評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來鳖孤,“玉大人者娱,你說我怎么就攤上這事∷沾В” “怎么了黄鳍?”我有些...
    開封第一講書人閱讀 169,589評論 0 363
  • 文/不壞的土叔 我叫張陵,是天一觀的道長平匈。 經常有香客問我框沟,道長,這世上最難降的妖魔是什么增炭? 我笑而不...
    開封第一講書人閱讀 60,188評論 1 300
  • 正文 為了忘掉前任忍燥,我火速辦了婚禮,結果婚禮上隙姿,老公的妹妹穿的比我還像新娘梅垄。我一直安慰自己,他們只是感情好输玷,可當我...
    茶點故事閱讀 69,185評論 6 398
  • 文/花漫 我一把揭開白布队丝。 她就那樣靜靜地躺著,像睡著了一般欲鹏。 火紅的嫁衣襯著肌膚如雪机久。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,785評論 1 314
  • 那天赔嚎,我揣著相機與錄音膘盖,去河邊找鬼胧弛。 笑死,一個胖子當著我的面吹牛侠畔,可吹牛的內容都是我干的结缚。 我是一名探鬼主播,決...
    沈念sama閱讀 41,220評論 3 423
  • 文/蒼蘭香墨 我猛地睜開眼践图,長吁一口氣:“原來是場噩夢啊……” “哼掺冠!你這毒婦竟也來了?” 一聲冷哼從身側響起码党,我...
    開封第一講書人閱讀 40,167評論 0 277
  • 序言:老撾萬榮一對情侶失蹤德崭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后揖盘,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體眉厨,經...
    沈念sama閱讀 46,698評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,767評論 3 343
  • 正文 我和宋清朗相戀三年兽狭,在試婚紗的時候發(fā)現(xiàn)自己被綠了憾股。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,912評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡箕慧,死狀恐怖服球,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情颠焦,我是刑警寧澤斩熊,帶...
    沈念sama閱讀 36,572評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站伐庭,受9級特大地震影響粉渠,放射性物質發(fā)生泄漏。R本人自食惡果不足惜圾另,卻給世界環(huán)境...
    茶點故事閱讀 42,254評論 3 336
  • 文/蒙蒙 一霸株、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧集乔,春花似錦去件、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,746評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至幼衰,卻和暖如春靴跛,著一層夾襖步出監(jiān)牢的瞬間缀雳,已是汗流浹背渡嚣。 一陣腳步聲響...
    開封第一講書人閱讀 33,859評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人识椰。 一個月前我還...
    沈念sama閱讀 49,359評論 3 379
  • 正文 我出身青樓绝葡,卻偏偏與公主長得像,于是被迫代替她去往敵國和親腹鹉。 傳聞我的和親對象是個殘疾皇子藏畅,可洞房花燭夜當晚...
    茶點故事閱讀 45,922評論 2 361

推薦閱讀更多精彩內容