Skip to content

Instantly share code, notes, and snippets.

@the-vampiire
Last active May 12, 2019 08:02
Show Gist options
  • Select an option

  • Save the-vampiire/d8eb9dd36faf1cb78aea505e9659c87d to your computer and use it in GitHub Desktop.

Select an option

Save the-vampiire/d8eb9dd36faf1cb78aea505e9659c87d to your computer and use it in GitHub Desktop.
easy mac osx postgresql and mongodb installation / usage

postgres

install

$ brew install postgresql

add shortcut function in your .bashrc or .zshrc file

$ vim ~/.zshrc

VIM commands

  • GG (go to end of file)
  • o (insert mode on new line)

paste the function below

# postgres service
postgres() {
  brew services $1 postgresql
}
  • esc (exit insert mode)
  • :x (write and quit, same as :wq)

source the profile to use the new command without quitting the terminal

$ source ~/.zshrc

usage

if you just installed then create a database for your user account (if you dont do this step you will need to log in as the default postgres user every time)

$ createdb <your user account name>

you dont have to use this db it is just a default for connecting to the shell

start the psql server

$ postgres start

enter psql shell

$ psql

exit psql shell

> \q

stop the psql server

$ postgres stop

mongodb

install

$ brew install mongodb-community@4.0

add shortcut function in your .bashrc or .zshrc file

$ vim ~/.zshrc

VIM commands

  • GG (go to end of file)
  • o (insert mode on new line)

paste the function below

# mongodb service
mongodb() {
  brew services $1 mongodb-community@4.0
}
  • esc (exit insert mode)
  • :x (write and quit, same as :wq)

source the profile to use the new command without quitting the terminal

$ source ~/.zshrc

usage

start the mongo server

$ mongodb start

enter mongo shell

$ mongo

exit mongo shell

> exit

stop the mongo server

$ mongodb stop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment