How to put psql on the path when using Postgres.app on OS X? - macos

I've installed Postgres93 on my Mac. I can open the application, and "Open psql" through the app which opens up a command line interface with psql.
However, when I type $ which psql nothing is returned. The installation path is /Applications/Postgres93.app. How do I make $ which psql show the correct result?
Mac OS X - Mavericks
PostgreSQL package, I'm not as sure about. I went here and downloaded it - http://postgresapp.com/

I just had postgres installed and was not able to run the psql command until I ran the following command in my terminal:
export PATH="/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH"
Now the terminal knows where to find postgres when I use the psql command.
Remember to replace the version number '9.5' with your current version.

I had the same problem with nothing showing for the which psql command till I run the command below to resolve it. The command provided below is just a little tweak of what has already been provided by others here. The only difference is, instead of providing a specific postgres version number in the command, you can simply tell postgres to use the latest postgres version by simply running the following command:
export
PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
And now my terminal was able to find the path to postgres when I run which psql.
Hope this helps.

On macOS Mojave these instructions work well:
If your Postgres has not been installed yet, I suggest you use the great "brew" package manager from here https://brew.sh/ :
$ brew cask install postgres
or you can install it usual way from the website
Put this to the bottom of your ~/.bash_profile file:
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:${PATH}"
Restart your terminal or restart your ~/.bash_profile directly with the command:
$ . ~/.bash_profile
Verify your installation:
$ psql --version

** Edited: to include a permanent fix, not just during your current session. **
I had this same problem, and also found a clear answer lacking in the docs.
To fix:
Download the new app, and follow the instructions to move it to the Applications folder
Add the new bundle to your path by typing the following in your Terminal (version number specific - mine is 9.4):
PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"
To fix the issue on a permanent basis, run the same line but with export in front:
export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

It appears that you installed Heroku's Postgres.app, which is a tool intended for throw-away testing and development. Add the contents of the bundle to your PATH by following the instructions in the Postgres.app documentation - see "command line tools".

On macos mojave i've added the following line on my ~/.profile :
export PATH=$PATH:/Library/PostgreSQL/10/bin
the psql command line client lies into this folder. i've used the enterprisedb installer.

I just experienced the same problem, and solved it by adding export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin to .bash_profile. Note that this line is version-specific, so be sure to check this line against your current version of Postgres.app.

Using Mac OS Monterey, the latest Homebrew (3.4.0) and postgres#13.
I was able to add psql to the path by using -
export PATH="/opt/homebrew/Cellar/postgresql#13/13.6/bin:$PATH"
Replace #13 and 13.6 with your version.
The latest homebrew install location seems to be /opt/homebrew/*

I'm using catalina 10.15.3 and I had the same issue after installing psql using homebrew. Then I noticed, homebrew mentioned
==> libpq
libpq is keg-only, which means it was not symlinked into /usr/local,
because conflicts with postgres formula.
If you need to have libpq first in your PATH run:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile
So, I ran 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile and psql was added to my path

In Mac, there is a SQL Shell application already under /Applications/PostgresSQL
try that
Also, you can run /Library/PostgreSQL/11/scripts/runpsql.sh

In my case, I installed Postgres12 and had the same issue. I had to look out for the location of my bin folder. It happened to be in /Applications/2ndQuadrant/PostgreSQL/12/bin. So I had to run export PATH="/Applications/2ndQuadrant/PostgreSQL/12/bin:$PATH" in my terminal and restart the terminal. That solved it.

Related

Local development on Mac M1 | Laravel & VueJs

I've just switched to MacOs - never used it before and I'm using Macbook M1 Pro, so a newbie here. Also, I've only started with web dev so I'm fairly new in this field as well.
Now, how should I proceed in order to set-up a local development enviroment - I plan to use mainly Laravel & VueJs?
Things I've done so far:
Installed VS code
Installe MAMP
Cloned my Git repository with project I was working on (Windows 10)
This is the part where I need help - I think I'm supposed to install Homebrew, but even if I follow the instructions on their website I can't get it working properly. It's installed but as soon as I close & reopen the terminal, it throws zsh: command not found: brew. The commands I'm used to - php artisan xyz or npm run watch don't work
Do you guys have some guide or step-by-step tutorial of what should I do in order to get my Laravel&Vue git project up & running on a localhost?
brew is installed in /usr/local/Homebrew/bin/brew (symlinked to /usr/local/bin/brew). Make sure /usr/local/bin is in your PATH, so that brew and newly installed Homebrew packages are available on the command line. This is typically setup by the ~/.zshrc file.
Troubleshooting steps:
Edit $HOME/.zshrc.
If export PATH is not found, add the following line. The important part is to ensure /usr/local/bin is present (and that :$PATH is last) to give it higher precedence. If the export PATH line exists, but commented, uncomment it.
export PATH=$HOME/bin:/usr/local/bin:$PATH
Restart your shell. .zshrc is loaded automatically at shell startup.
Check for brew with the which command:
$ which brew
/usr/local/bin/brew
Update
This suggestion here fixed my issues: https://stackoverflow.com/a/66521797/9682588
So, what I did was:
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile

ZSH: Command not found - after update macOS to 10.15.1

Yesterday I was using all my installed packages without any problem such as mysql, composer, php, brew and co...
However, today I started my MacBook and typed mysql and I got: zsh: command not found: mysql. Not even brew is working anymore and I don't know why.. this is my .zshrc config file and I don't know why it isn't working.
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:~/.composer/vendor/bin:$PATH
Any ideas how to fix this?
Yuck, how did that happen? Try this:
PATH=/bin:/usr/bin:/usr/local/bin:$PATH
export PATH
Whether this works is going to depend on where you have been installing user executables. If you're using homebrew, I would expect it to be /usr/local/bin but perhaps it is something different in your case? You might want to try putting /usr/local/bin first so things installed by homebrew get picked up before the defaults in /usr/bin and /bin (this is what I do, and I'm still alive to talk about it...)
You could also change your default shell back to Bash:
brew install bash
echo '/usr/local/bin/bash' >> /etc/shells
chsh
You might need to use sudo on line 2.

installing .net core on mac

I am installing .net core on a mac and hoping to play around with it a bit on vs code. I am following the steps from
https://www.microsoft.com/net/core#macosx.
However, when I run
dotnet new
I get command not found on bash.
I have followed these previous steps
brew update
brew install openssl
brew link --force openssl
I have also downloaded the core package (installed successfully). I do not see any other steps. Wondering if I am missing a step or how to identify what is missing?
Sometimes I am not sure why the installer doesn't add the PATH to your environment.
Run below in terminal and reopen the terminal:
echo 'export PATH="$PATH:/usr/local/share/dotnet"' >> ~/.bashrc
(Note: If you are using zsh or other shells, please change the above ~/.bashrc to the initialize script of your shell, e.g. ~/.zshrc)
I ran into this same problem earlier today. The fix for me was to close out all Terminal windows, open a new one, then re-run the command.

How to update cURL on OSX El Capitan?

I'm new using Mac and I'd like to upgrade the available cURL-7.43.0 to the last version cURL-7.47.1?
I'm looking at some pages, but they say to avoid upgrading the originals on OSX.
Any help please?
Thanks
Take a look at installing homebrew, it's a package manager that allow you to install and update binaries without overwriting your original ones.
You need then to prepend your PATH with homebrew's (/usr/local/bin by default).
If you don't when you run curl the system will fetch the default OSX one (/usr/bin/curl) which isn't updated.
Use which curl when you're done to check !
I had this issue as well with OSx locating curl at /usr/bin. If you install curl with brew install curl and then do brew info curl it will tell you the following near the bottom of the post-op output:
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile
After running that command to update ~/.bash_profile you need to source it by executing . ~/.bash_profile

Mongod: Command Not Found (OS X)

I am trying to test MongoDB and I have it all downloaded and moved into the root folder. I can navigate to the folder that holds the mongod, but when I try to run it by typing "mongod" into my terminal, I get a message that says:
"mongod: command not found"
Both answers above are correct.
You can either specify the path in one of the following files: .profile, .bashrc, or .bash_profile
export PATH="$PATH:/usr/local/mongodb/bin"
then call the daemon or the shell directly
mongod
mongo
Or for the commands not in the $PATH, use ./mongo or ./mongod from the directory containing these files. This solution can be verbose has you will have to eventually append the whole path when calling these commands from another directory.
/usr/local/mongodb/bin/mongod
or
/usr/local/mongodb/bin$ ./mongod
"Mongod" isn't a stand-alone command. You need to run the command like this:
./mongodb/bin/mongod
I used this webpage to help me answer this question.
This worked for me:
brew tap mongodb/brew
brew install mongodb-community#4.2
mongod
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
For example, install 64bit MongoDB 2.6.12 on macOS Catalina.
(for newest versions you may go to https://www.mongodb.com/download-center/community for your platform).
Download, extract and move:
wget http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.12.tgz
tar xzf mongodb-osx-x86_64-2.6.12.tgz
mv mongodb-osx-x86_64-2.6.12/ /usr/local/mongodb/
Add to file ~/.zshrc this:
export PATH="$PATH:/usr/local/mongodb/bin"
PS: .bash_profile or .profile not worked in my case
Reload terminal (or close, open it):
source ~/.zshrc
Make directory for data and set rights:
mkdir -p ~/data/db
chown -R mongodb.mongodb ~/data/db
Run MongoDB:
mongod --dbpath ~/data/db
You need to add the name of the folder that contains the command mongod into your PATH so your shell knows where to find it.
So, if mongod is in /usr/bin/freddyfrog, you would edit ~/.profile and find the line that says PATH= and edit it to look like this:
export PATH=${PATH}:/usr/bin/freddyfrog
Then login again to make it take effect.
I received the same error message because I used the wrong command to run mongod (meant for M1s) for my 2019 MacBook with an Intel processor. You can skip past Homebrew updates and MongoDB installation but here's how I resolved my issue:
Download Xcode Command Line tools.
xcode-select --install
Allow Homebrew to add and access MongoDB:
brew tap mongodb/brew
Update Homebrew:
brew update
Install MongoDB Community Edition (#6.0 is the latest version at the time of this post):
brew install mongodb-community#6.0
macOS with Intel processors:
mongod --config /usr/local/etc/mongod.conf --fork
macOS with Apple M1 processors:
mongod --config /opt/homebrew/etc/mongod.conf --fork
Then open the shell:
mongosh
Or just run mongod.
Official documentation on installation here.
3 steps:
Step 1:
export PATH="$PATH:/usr/local/mongodb/bin"
OR
export PATH="$PATH:/usr/local/opt/mongodb#3.2/bin"
(replace version number with your local version)
The first step will allow you to run the command, but will get you another error: "/data/db does not exit" so you have to
Step 2 :
sudo mkdir -p /data/db
Now /data/db is read only, but it has to be writable also so
Step 3 :
sudo chown -R USERNAME /data/db
I was trying to install a previous version (3.6) using latest documentation (4.2 is already released). So, they now call it mongodb-community#3.6.
In order to update PATH for such setup, the statement should be
export PATH="$PATH:/usr/local/opt/mongodb-community#3.6/bin";
I got hint from #retroGiant 's answer
run this command, it works:
brew services start mongodb-community#4.0
I have installed mongodb-community#3.2, was facing the same issue. I followed below steps.
open bash profile in any editor (you can also try - vi ~/.bash_profile)
write this export PATH="$PATH:/usr/local/opt/mongodb-community#3.2/bin" & save.
do this . source ~/.bash_profile
In root directory
sudo mkdir data
cd data
mkdir db
then
sudo chown -R yourUsername /data/
copy path of your mongodb/bin downloaded folder (I suggest you put it in home folder not root dir)
in terminal
export PATH="paste the link here :$PATH"
now it should work but if not
In case you are using different Unix shell and
trying to execute mongod within visual studio code( for example ),
make sure to read the documentation to link PATH.
For example, if you are using zsh create .zprofile in your home directory.
touch .zprofile
copy your previously made PATH into .zprofile
Now everything should work as expected.
I was looking for the same and later I have found that now it's very straight forward to install the new MongoDB Community Edition like below:
Installing MongoDB 6.0 Community Edition
brew tap mongodb/brew
Note: If you haven't yet install brew then follow this link: https://brew.sh/#install
Update Homebrew
brew update
Install MongoDB
brew install mongodb-community#6.0
The installation includes the following binaries:
The mongod server
The mongos sharded cluster query router
The MongoDB Shell, mongosh
Run MongoDB Community Edition
To run MongoDB (i.e. the mongod process) as a macOS service, run:
brew services start mongodb-community#6.0
To stop a mongod running as a macOS service, use the following command as needed:
brew services stop mongodb-community#6.0
MongoDB 5.0 issue resolved - SEP/2022
do following steps
step 1: open a .zshrc file if it does not exist it will create by itself by following the command. For opening or creating a .zshrc file below command is the same.
vim .zshrc
step 2: insert value in it by pressing 'i'
step 3: insert the below command there or paste it there.
export PATH="$PATH:/usr/local/opt/mongodb-community#5.0/bin"
step 4: to exit click on esc key and the write :wq
step 5: Close the terminal and reopen it and type the below command
mongo
Output
MongoDB shell version v5.0.11
connecting to: mongodb://127.0.0.1:279021/?
compressors=disabled&gssapiServiceName=mongodb
Successfully integrated mongo 🎉 🎉 🎉
happy coding !!
If you use brew then check the path:
brew list
brew list mongodb-community#...
then add it to .zshrc
zsh: command not found: mongo
after that use mongosh instead of mongo
This answer is a little bit unrelated, but if you using vscode & would like to interact with mongoDB using command line, have a read.
I was looking to use mongod command as well (as i love to use command to interact with mongoDB), but after several attempts of install i completely give up. Until i found this, the mongoDB vscode extension.
The extension is loading the data pretty fast just like mongod command compare to mongo compass. It allow you to perform CRUD & aggregation in the mongoDB playground, and most importantly you able to retrieve the command on next execution by storing your command in a file with .mongodb extension.
*Update: After using it several weeks, everything is nice, just need to make sure you connecting to the right mongoDB connection (if you establish few different connection)

Resources