Read-Only File System When Attempting Mkdir /Data/Db on Mac [Closed]
I Am Trying to Create a New Folder in the Main Directory Tried All Kinds of Examples Sudo Mkdir /Data/Db Sudo Mkdir -P /Data/Db I Keep Getting Mkdir: /Data...
I am trying to create a new folder in the main directory
Tried all kinds of examples
sudo mkdir /data/db
sudo mkdir -p /data/db
I keep getting
mkdir: /data: Read-only file system
16 Answers
If you have a Mac and updated to Catalina or more recent version, then the root folder is no longer writable.
I just changed the directory somewhere else.
Been using this command for now
mongod --dbpath=/Users/user/data/db
from the official docs
install homebrew and run the following commands
sudo chown -R $(whoami) $(brew --prefix)/*
then
brew tap mongodb/brew
then
brew install mongodb-community@4.2
and
brew services start mongodb-community
or
mongod --config /usr/local/etc/mongod.conf
then
ps aux | grep -v grep | grep mongod
and
mongo
to verify you can run show dbs in the mongo shell
With the new macOS Catalina update, the folder /data/db becomes read-only, you cannot modify it. Follow this procedure to create a DB in another folder:
Change
mongoddirectory :sudo mongod --dbpath /System/Volumes/Data/data/dbGive it an alias to use it as
mongod:alias mongod="sudo mongod --dbpath /System/Volumes/Data/data/db"Just type
mongodin your terminal, it should work.
Extra => If you need to give it current user rights, use this line of code :
sudo chown -R $(whoami) /System/Volumes/Data/data/db
(Just for info -> $(whoami) is just a variable that returns your current user)
To make a permanent change of the path of mongod db folder.
Following these docs they say roughly this. If mongod is started with brew services:
$ brew services start mongodb-community@4.2
It will use config file at path /usr/local/etc/mongod.conf
To fix this, edit the config file:
$ vim /usr/local/etc/mongod.conf
And change the dbPath e.g. to your home directory like this:
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /Users/<username>/data/db
net:
bindIp: 127.0.0.1
Save the file and restart mongod with brew:
$ brew services restart mongodb-community@4.2