티스토리 뷰

반응형

Homebrew로 mongodb 설치하기

mongodb 설치가이드의 내용을 따라 설치를 진행하니 설치 및 서비스 시작/정지 까지 잘 진행됐다. mogodb는 설치 버젼에 따라 친절하게 방법을 제공하고 있으니 설치 버젼을 선택하면 된다.

# Xcode command-line가 이미 설치된 경우, 버젼이 맞지 않아 재설치가 필요한 경우에 사용
$ xcode-select --install

$ brew tap mongodb/brew

# 설치하려는 버젼에 따라 다름
$ brew install mongodb-community@4.2

$ brew services start mongodb-community@4.2

$ brew services stop mongodb-community@4.2

$ brew services list

$ brew tap | grep mongodb

$ brew install mongodb-database-tools

# 여기서 zshrc 등을 사용하는 경우에 명령어를 못 찾는 경우
$ mongo
$ zsh: command not found: mongo

위에 대략적인 가이드 문서를 따라 설치를 진행했지만, mongo 실행 명령어를 못 찾는다. 그래서 다른 사람들은 어떤가 검색해보면 대부분 mongo 명령어를 바로 실행 가능한 것 같고 data 설정을 위한 사용자 설정 등의 단계로 대부분 넘어갔다. 아래 mongodb 가이드 문서에 보면 Intel Processor와 Apple M1 Processor의 경우에 설치 및 환경 구성 경로가 다름을 알 수 있다.

그래서 brew을 이용해서 설치된 경로를 확인하고 zshrc에 PATH 등록을 해줘야 한다. brew로 관리되는 서비스 목록을 아래 명령어로 확인한다.

$ brew services list

 

Mongo 설치 경로 확인 및 설정

그리고 brew info 명령어를 이용하여 mongodb의 설치된 경로를 확인한다.

$ brew info mongodb-community@4.2
mongodb/brew/mongodb-community@4.2: stable 4.2.18 [keg-only]
High-performance, schema-free, document-oriented database
https://www.mongodb.com/
/opt/homebrew/Cellar/mongodb-community@4.2/4.2.18 (21 files, 306.8MB)
  Built from source on 2022-02-14 at 10:52:32
From: https://github.com/mongodb/homebrew-brew/blob/HEAD/Formula/mongodb-community@4.2.rb
==> Caveats
mongodb-community@4.2 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have mongodb-community@4.2 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/mongodb-community@4.2/bin:$PATH"' >> ~/.zshrc


To restart mongodb/brew/mongodb-community@4.2 after an upgrade:
  brew services restart mongodb/brew/mongodb-community@4.2
Or, if you don't want/need a background service you can just run:
  mongod --config /opt/homebrew/etc/mongod.conf

친절하게 export 해야 하는 정보에 대해서 'If you need to have mongodb-community@4.2 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/mongodb-community@4.2/bin:$PATH"' >> ~/.zshrc' 알려주고 있다.

$ vi ~/.zshrc

vi편집기을 이용해서 아래 내용 추가
...
export PATH="/opt/homebrew/Cellar/mongodb-community@4.2/4.2.18/bin:$PATH"
...

 

결과 확인

이제 새로운 터미널을 열고 mongo 명령어를 입력하여 'mongo shell'에 정상적으로 접속할 수 있다.

$ mongo
MongoDB shell version v4.2.18
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2022-02-14T12:07:11.119+0900 I  CONTROL  [js] machdep.cpu.extfeatures unavailable
Implicit session: session { "id" : UUID("4cba5106-27c0-4701-abf6-ca6b6c9180b4") }
MongoDB server version: 4.2.18
Server has startup warnings:
2022-02-14T11:38:50.673+0900 I  CONTROL  [initandlisten]
2022-02-14T11:38:50.673+0900 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2022-02-14T11:38:50.673+0900 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2022-02-14T11:38:50.673+0900 I  CONTROL  [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>

- 끝 -

반응형
댓글