Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read-only file system when attempting mkdir /data/db on Mac [closed]

People also ask

How do I change a read only file in Linux?

Use chmod -v u+rw filename to give yourself read and write permissions. You can omit the r if you already have read permissions. Once you have write permissions, you'll be able to delete the file.


If you have Mac and updated to Catalina than 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 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

install homebrew and run the following commands

sudo chown -R $(whoami) $(brew --prefix)/*

then

brew tap mongodb/brew

then

brew install [email protected]

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:

  1. Change mongod directory :

    sudo mongod --dbpath /System/Volumes/Data/data/db

  2. Give it an alias to use it as mongod:

    alias mongod="sudo mongod --dbpath /System/Volumes/Data/data/db"

  3. Just type mongod in 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 [email protected]

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 [email protected]

You can't create a folder on the root directory on Mac Catalina anymore!

https://www.apple.com/macos/catalina/features/

Dedicated system volume

macOS Catalina runs in a dedicated, read-only system volume โ€” which means it is completely separate from all other data and helps improve the reliability of macOS.

# macOS Catalina, mkdir path
$ sudo mkdir -p /System/Volumes/Data/data/db

# give permissions
$ sudo chown -R `id -un` /System/Volumes/Data/data/db

# macOS 10.14.x -
$ sudo mkdir -p /data/db

# macOS 10.15.x +
$ sudo mkdir -p /System/Volumes/Data/data/db

refs

https://discussions.apple.com/thread/250720711

https://zellwk.com/blog/install-mongodb/

https://www.youtube.com/watch?v=DX15WbKidXY


So, with macOS Catalina Apple created a new Volume for security purposes. If youโ€™re on macOS Catalina, you'll need to create the /data/db folder in System/Volumes/Data.

Follow these commands

  1. sudo mkdir -p /System/Volumes/Data/data/db
  2. sudo chown -R id -un /System/Volumes/Data/data/db

Start MongoDB

  1. brew services run mongodb-community

  2. Enjoy ๐Ÿ˜‰