I'm installing MongoDB for a Node / Express tutorial and upon creation of the /data/db folder and the following command:
sudo chown 'id -u' /data/db
I received the following error:
chown: id -u: illegal user name
You can look for the current username and then try setting the permissions.
$ whoami
username
$ sudo chown username /data/db
Hope that helps.
The reason this failed is because your syntax was wrong and you misinterpreted the quoting from the source where you found it. You need to use a quote like this to execute the id
command:
chown `id -u` /data/db
See the difference?
Also you seem to have arrived here at a misconception of how to install mongodb, and possibly have gone for a build from a tarball. The /data/db
path is not required, it's just the default location.
But you generally can get a package install for your system:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
These will typically lay out an installation with a directory structure appropriate to your system conventions, and create a mongodb
user under which the mongod
process runs, with all appropriate permissions. They typically have a config file that you can set options in as well. The process is also typically set-up as a "service", so you don't need to manually invoke it each time you want to use.
You can specify the --dbpath option on startup or within a config file section, which of course is loaded by the --config option.
At any rate you should generally run mongod
processes as their own user (not root) using the options and permissions on data and logging directories set for that user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With