I created /data/db in root directory and ran ./mongod:
[initandlisten] exception in initAndListen: 20 Attempted to create a lock fi
Fix the permissions of /data/db (or /var/lib/mongodb):
sudo chown -R mongodb: /data/db
then restart MongoDB e.g. using
sudo systemctl restart mongod
In case that does not help, check your error message if you are using a data directory different to /var/lib/mongodb. In that case run
sudo chown -R mongodb:
source