How do I install redis 5.0.14 using homebrew - macos

I need to install redis version 5.0.14 on my mac using brew.
I have tried multiple ways like brew install redis#5.0.14, redis#5.0, redis#50, redis#5 but nothing seems to work!!
I was able to find out on https://formulae.brew.sh/ that the options that can be installed using brew are redis, redis#4.0, redis#3.2 . But I need to install redis 5.0.14 or basically above 5.0.6 because that is the version we have on our production. Can anyone help me out on this?
I have seen a way here that suggests to checkout specific homebrew formulae version but that would become too messy if something goes wrong. I would prefer a straight forward way if there is one.

Given that the Redis version you require is not available via homebrew, your question is unanswerable. However, given how good docker is on macOS, I have taken to using that rather than homebrew for lots of version-related problems.
With docker:
I can pull any version I want,
it's all isolated from my core macOS,
just as performant,
readily deletable,
simple to have many versions,
switchable between versions,
repeatable across platforms and
configurable by script.
Official image here.
So, in concrete terms, you could run Redis 5.0.14 as a daemon like this:
docker run --name some-redis -d redis:5.0.14
and then connect to that same container and run redis-cli inside it like this:
docker exec -it some-redis redis-cli PING
PONG
Or you could run Redis in the container but expose its port 6379 as port 65000 to your regular macOS applications like this:
docker run --name some-redis -p 65000:6379 -d redis:5.0.14
Then it is accessible to your macOS applications, such as redis-cli like this:
redis-cli -p 65000 info | grep redis_version
redis_version:5.0.14

The version you're looking for is not available on brew unfortunately.
bruno#pop-os ~> brew info --json redis | jq -r '.[].versioned_formulae[]'
redis#4.0
redis#3.2
You could get the source code from here: https://github.com/redis/redis/releases/tag/5.0.14
extract it to some directory, to run Redis with the default configuration just type:
% cd src
% ./redis-server
If you want to provide your redis.conf, you have to run it using an additional
parameter (the path of the configuration file):
% cd src
% ./redis-server /path/to/redis.conf
It is possible to alter the Redis configuration by passing parameters directly
as options using the command line. Examples:
% ./redis-server --port 9999 --replicaof 127.0.0.1 6379
% ./redis-server /etc/redis/6379.conf --loglevel debug
All the options in redis.conf are also supported as options using the command
line, with exactly the same name.
Optionally you could use Docker, docker run --name some-redis -d redis:5.0.14

brew update
brew install redis
To have launchd start redis now and restart at login:
brew services start redis
To stop it, just run:
brew services stop redis
Test if Redis server is running.
redis-cli ping

Related

Alias for Start/Stop Postgres as root

I have installed Postgres on my M1 mac using a dmg file which I downloaded from their website. The homebrew installation was causing some issues, that's why I installed it this way.
Previously with homebrew I could start/stop postgres using brew services start/stop postgres. Currently I have to do this
sudo -u postgres pg_ctl -D /Library/PostgreSQL/14/data start/stop to start/stop the server. I tried to make things a bit easier by adding an alias to .zshrc file, but as I learned I can't just add a command to shell with sudo like that.
My question is there any way to add an alias to simplify the start/stop of postgres.
Use a function instead of an alias:
start_postgres() {sudo -u postgres pg_ctl -D /Library/PostgreSQL/14/data start}

How to set path to kubectl when installed using gcloud components install?

Ok, I installed kubectl in the following way on my Mac:
1) installed gcloud using homebrew
2) installed kubectl using gcloud components install.
I want to run a shell script that calls kubectl directly. However, I get an error.
$ kubectl version
-bash: kubectl: command not found
I expected gcloud components install to set path variables so that I can call kubectl. Looks like that has not happened. I searched for kubectl in my mac but was not able to find it.
How can I get kubectl to work from command line?
Short answer:
On macOS, you may need to add a symlink: sudo ln /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/kubectl /usr/local/bin/kubectl
Long answer:
I believe this is caused by installing kubectl via homebrew, then via gcloud, and then uninstalling the homebrew managed tool. homebrew will remove its symlink but gcloud doesn't add it back even when you reinstall kubectl.
To see if this is affecting you on macOS:
See if gcloud has installed kubectl: gcloud info | grep -i kubectl
If you are having the problem I am, I'd expect to see the output look something like this:
kubectl: [2019.05.31]
Kubectl on PATH: [False]
When working you should see something like this:
kubectl: [2019.05.31]
Kubectl on PATH: [/usr/local/bin/kubectl]
/usr/local/bin/kubectl
Check for the symlink: ls -la /usr/local/bin | grep -i google-cloud-sdk. That will show your links to google cloud binaries.
If kubectl isn't on the list then run sudo ln /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/kubectl /usr/local/bin/kubectl
The gcloud info command will tell you if and where kubectl is installed.
Per https://kubernetes.io/docs/tasks/tools/install-kubectl/, you can install kubectl with brew install kubernetes-cli. Alternatively, you can install the Google Cloud SDK per https://cloud.google.com/sdk/docs/quickstart-macos, and then install kubectl with gcloud components install kubectl.
Just to update and add more clarity around this:
If you did not install kubectl via Homebrew but chose to do
gcloud components install kubectl
instead then the binary is installed inside the bin folder of your gcloud install folder. Even if your gcloud bin folder is already on your shell's PATH it wont see kubectl right away unless you start a new shell or run hash -r (bash / zsh) to tell your shell to discard its cached paths.
Thanks to #mark, I was able to sort this out, but I feel modifying the $PATH is a better approach. I also found that the Caskroom folder was in a different spot. So I recommend adding this to the relevant rc file:
export PATH="`brew --prefix`/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin:$PATH"

How to shut down rethinkdb running on Mac OSX

Note: We love RethinkDB but our current project does not use it so we need to free up resources on our local machine ...
We installed RethinkDB using homebrew:
brew update && brew install rethinkdb
And added the rethinkdb process to our plist as per the instructions in:
http://rethinkdb.com/docs/start-on-startup/
But now we need to shut it down to free-up the 8080 port for another service.
What command do we need to run? (thanks!)
Do this in the terminal
check to see if you started it using brew
$ brew services list
stop rethinkdb:
$ brew services stop rethinkdb
restart:
$ brew services start rethinkdb
Like this, I think, if you used launchctl:
sudo launchctl unload -w /Library/LaunchDaemons/com.rethinkdb.server.plist

Postgres - FATAL: database files are incompatible with server

After restarting my MacBook Pro I am unable to start the database server:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I checked the logs and the following line appears over and over again:
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.0.4.
9.0.4 was the version that came preinstalled on the mac, 9.2[.4] is the version I installed via Homebrew.
As mentioned, this used to work before the restart, so it can't actually be a compiling issue. I also re-ran initdb /usr/local/var/postgres -E utf8 and the file still exists.
If you recently upgraded postgres to latest version, you can run the below command to upgrade your postgres data directory retaining all data:
brew postgresql-upgrade-database
The above command is taken from the output of brew info postgres
Note: this won't work for upgrading from 14 to 15 as of recent testing.
If you are looking for the nuclear option (delete all data and get a fresh database), you can do:
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
and then you'll need to rake db:setup and rake db:migrate from your Rails app to get setup again.
Try this :
https://gist.github.com/joho/3735740
It worked perfectly for me.
In the end it also generates you 2 bash scripts to check your DB and remove the old cluster.
Really Awesome.
see: http://www.postgresql.org/docs/9.2/static/pgupgrade.html to understand more.
Found on internet, this solution work fine for me.
When I tried to start postgresql server after upgrade to OS X 10.10 Yosemite, I encountered with a next problem:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Okay, lets take a look into server logs:
cat /usr/local/var/postgres/server.log
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.5.
So, we need to follow a few steps after upgrade postgresql:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres92
brew update
brew upgrade postgresql
initdb /usr/local/var/postgres -E utf8
pg_upgrade -b /usr/local/Cellar/postgresql/9.2.3/bin -B /usr/local/Cellar/postgresql/9.3.5_1/bin -d /usr/local/var/postgres92 -D /usr/local/var/postgres
cp /usr/local/Cellar/postgresql/9.3.5_1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
rm -rf /usr/local/var/postgres92
That's it.
If you want to keep the previous version of postgres, use brew switch:
$ brew info postgresql
postgresql: stable 10.5 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
Conflicts with:
postgres-xc (because postgresql and postgres-xc install the same binaries.)
/usr/local/Cellar/postgresql/9.6.3 (3,259 files, 36.6MB)
Poured from bottle on 2017-07-09 at 22:15:41
/usr/local/Cellar/postgresql/10.5 (1,705 files, 20.8MB) *
Poured from bottle on 2018-11-04 at 15:13:13
$ brew switch postgresql 9.6.3
$ brew services stop postgresql
$ brew services start postgresql
Otherwise, consider this brew command to migrate existing data: brew postgresql-upgrade-database. Check out the source code.
As #Gowtham mentioned, you can solve this problem by executing a brew command
brew postgresql-upgrade-database
The above command is taken from the output of brew info postgres
However, don't forget to stop the postgres service before executing it, use the following command:
`brew services stop postgresql
you may have to start the service again.
So the final order of commands are:
brew services stop postgresql
brew postgresql-upgrade-database
brew services start postgresql
Similar to these answers (1, 2), my Postgres database files were incompatible to my Postgres version after upgrading to postgresql 13.3.
Unfortunately, upgrading my Postgres data directory failed.
$ brew postgresql-upgrade-database
...
Setting next OID for new cluster
*failure*
Consult the last few lines of "pg_upgrade_utility.log" for
the probable cause of the failure.
Failure, exiting
Error: Upgrading postgresql data from 12 to 13 failed!
==> Removing empty postgresql initdb database...
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres...
Error: Failure while executing; `/usr/local/opt/postgresql/bin/pg_upgrade -r -b /usr/local/Cellar/postgresql#12/12.7/bin -B /usr/local/opt/postgresql/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres -j 8` exited with 1.
My workaround for this was to reinstall postgresql 12.7.
$ brew reinstall postgresql#12
$ brew services start postgresql#12
This can also occur when running a new Postgres in Docker, and your old volume isn't updated.
If you don't need to keep your data easiest is to clear the old volumes in the docker folder, in Linux that's here:
/var/lib/docker/volumes
It happened for me when I was trying to start Postgres12 with postgres11 mounted volume. Just deleting the mounted volume for postgres11 and restart worked for me.
Previously I was using:
docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:11
I deleted /Users/champ/postgres and restarted postgres 12, using
docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:12
brew info postgres will give you hints Like To migrate existing data from a previous major version of PostgreSQL run:
So in my case removing the old one rm -rf /usr/local/var/postgres.old and upgrading the DB brew postgresql-upgrade-database
A stale postmaster.pid file caused this for me.
Simply navigate to your postgres directory /Users/st/Library/Application Support/Postgres/, for me, that's:
cd '/Users/<username>/Library/Application Support/Postgres/var-10'
Then delete the file postmaster.pid. Restart postgres and it will work.
To me works with this command:
brew install --build-from-source postgresql#12
Then started Postgres:
brew services start postgresql#12
You can also check the port 5432 is listen:
netstat -nl |grep 5432

Postgres.app Could not start on port 5432

I'm using http://postgresapp.com. In the menubar it gives the error " Could not start on port 5432." Similarly if I try to start the server from the terminal, I get:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I also ran pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
and got the output server starting but still get the same errors when connecting to psql.
If you are running your server on a macOS machine and installed Postgres through Homebrew, you can stop the current instance like this:
brew services stop postgresql
Then click the Elephant in the native menu-bar at the top of the screen and it should successfully startup.
You can stop the process by finding the PID with
lsof -i :5432
and then killing it with
kill -9 <PID>
If you've installed Postgres via another method (for example, from www.postgresql.org) and it's starting automatically at startup, you can prevent that Postgres from starting via the following:
sudo launchctl unload /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist
sudo rm -f /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist
TIP: use tab to autocomplete after the com.edb.launchd part to figure out what version is loading.
Restart Postgres.app and you should be good to go.
(from http://forums.enterprisedb.com/posts/list/1831.page;jsessionid=70621DC48C99EDE663A6A594B05F1A02#6782)
I was just having this exact issue. When I ran which psql it was pointing at the Postgres client tools installed with Lion:
/usr/bin/psql
Using a hint from Frank Wiles I ran ps auxw | grep post to confirm that postgres was running and that it was running on the right port, that also showed me the postgres.app path:
/Applications/Postgres.app/Contents/MacOS/bin/postgres.
So I edited by .bash_profile to export that directory. On first effort I added it to the end of the path. When I ran echo $PATH I could see that usr/bin was the first thing in the path, and which psql still gave the /usr/bin path. At that point a friend guided me in the right direction:
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:${PATH}"
Start a new terminal window, then run which psql -- it should point to the postgres.app location and psql should fire up the postgres shell. Works fine now.
I have tried just about every solution to this problem that is out there. For me it always happens when my MacBook's battery dies, even if the computer is already sleeping. I was poking around in ~/Library/Application\ Support/Postgres/var-9.4 and I discovered another postmaster.pid file that I had not seen before. I deleted it, and now everything is back up and running! I am running the Postgres.app version, not the brew version.
Steps I took:
Make sure postgres.app is not running.
Run rm ~/Library/Application\ Support/Postgres/var-9.$X/postmaster.pid
If you don't have a var-9.$X directory, just run rm ~/Library/Application\ Support/Postgres/postmaster.pid
Restart postgres.app
Get back to developing cool stuff.
This command is a one-liner that instantly kills all PostgresSQL processes.
sudo kill -kill $(sudo lsof -t -i :5432)
This fixed all my problems on Mac OSX Mojave 10.14.1.
You my have another instance of postgres running, that is the only application interested in this port. You should use netstat and ps to determine this. Then stop the instance and uninstall it, you mayhave installed enterpiseDb for example, that is what I did.
I generally face this issue on my mac, and this fixes it for me always
rm /usr/local/var/postgres/postmaster.pid
brew services restart postgresql
Hope this is helpful
I had a similar problem where I could not connect to the Postgres.app even though the app itself said that it is running on port 5432.
I am not sure why, but even when I quit the app and checked that no postgres processes was running with ps -a. these files existed:
/tmp/.s.PGSQL.5432
and
/tmp/.s.PGSQL.5432.lock
My solution was to delete these files and then start the postgres.app again.
This is what worked for me:
$ sudo pkill -u postgres
Props to this resource:
https://github.com/PostgresApp/PostgresApp/issues/197#issuecomment-474534056
It can also happen that the PID is taken.
This ocurred to me when the Computer suffered an unexpected reboot.
If so, you must go to:
˜/Library/Application Support/Postgres/var-9.4
You can check that path in Postgres.app Preferences dialog.
And then, just remove the pid file
sudo rm postmaster.pid
And the server starts up right away.
When trying to open the Postgres app was getting that same error regarding post 5432 (on Mac OSX 10.10.5)
I did:
$ lsof -i | grep LISTEN
Saw which PID was running postgres at that port, did:
$ killall {pid} and then $ brew uninstall postgres
After that, restarted my Mac, and ran:
$ lsof -i | grep LISTEN again just to make sure. Saw no postgres running anywhere and was able to open the Postgres app without getting that warning.
Then I reinstalled postgres with $ brew install postgres
ANOTHER OPTION:
(I also tried this one time when the above approach didn't work and I could not kill any of the PID)
$ ps auxw | grep post
Saw a slew postgres processes, which I then sudo kill <PID>
Everything working fine now.
For those using mac, this code worked for me like charm.
sudo pkill -u postgres
At a guess, something else had taken port 5432 so the app chose to run on 5433 instead.
Why not just connect to Pg on port 5433, if that's where it's running? You have a /tmp/.s.PGSQL.5432 socket file, so you can connect with psql -p 5433 for UNIX domain socket connections. It'll also be listening on the same port with TCP/IP, so you can use psql -h localhost -p 5433 for TCP/IP and have your apps connect to port 5433 instead of 5432.
Change your .psqlrc to set the new port as default and you can forget it isn't on the default port.
I had similar problem when trying to use postgresql with rails. Updating my Gemfile to use new version of gem pg solve this problem for me. (gem pg version 0.16.0 works). In the Gemfile use:
gem 'pg', '0.16.0'
then run the following to update the gem
bundle install --without production
bundle update
bundle install
Mine failed to start up suddenly, and when I checked Console.app I saw:
com.heroku.postgres-service:
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=5432001, size=3874816, 03600).
HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter. You can either reduce the request size or reconfigure the kernel with larger SHMALL. To reduce the request size (currently 3874816 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
The PostgreSQL documentation contains more information about shared memory configuration.
It turns out Postgres wouldn't start up because I had Wireshark (and X11) running. It worked fine after I quit Wireshark.
Good luck!
I resolved this problem by
Identifying what was running on port 5432 by using "netstat" in the CL, which was postgreSQL not Postgres
I located the directory that contained postgreSQL, which was root/Library/PostgreSQL
I ensured an instants of the application wasn't running via Activity Monitor
Then I deleted the folder and rebooted! Everything was fine!
Somehow I totally forgot that this socket file will be hidden because of the dot. Make sure you use ls -A /tmp/.s.PGSQL.5432 if you are checking to see if the socket is actually there.
You most likely has a PostgreSQL installed, deleted it and installed it again. PostgreSQL typically used port 5432 but if not available, increases to the next available one, in this case 5433. So, you probably chose this port on your second install.
I think you should check file:
/etc/services
and adjust rows below for your expected port number:
postgresql 5432/udp # PostgreSQL Database
postgresql 5432/tcp # PostgreSQL Database
After this you should restart your computer (simplest way).
I had the same issues:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
In my case it was a corrupt host file on my mac. I was missing:
127.0.0.1 localhost
A quick easy way to check is to open terminal and type:
ping localhost
or:
scutil -r localhost
More info here
Hope it helps.
Netstat, ps aux, etc ... none showed 5432 in use. Checked /Library. Found PG9.6 old install still there. Did rm -rf and bang. Version 11 works fine.
I was losing my mind over this problem! i kept running
lsof -i | grep 5432
and nothing was showing up!
finally i ran it using sudo and a potgres client showed up.
so if anyone else has tried the lsof and went nowhere, try it with sudo.
sudo lsof -i | grep 5432
and then
sudo kill <the_pid_from_postgresql_found_from_lsof>
The same problem just happened to me. I had Postgres.app 9.2.4.1 running since a while. When I updated Mac OS X to 10.8.5, after the mandatory reboot it was not working anymore. I tried several things, including updating to 9.2.4.3 and neither after another reboot it was working.
I had to open the file /Users/$USER/Library/Application Support/Postgres/var/postgresql.conf and to:
uncomment line unix_socket_permissions = 0777
uncomment and adapt line unix_socket_directory = '/tmp'
After a restart, Postgres.app was running like a charm.
A file named "postmaster.pid" (in my $PGDATA directory) were preventing postgresql to start. It was a zombie file, placed there 10 days ago and when I brutally shut down the computer (pulling the plug, literally), no clean up process had the opportunity to remove that file.
beside all the helpful answers, you might also want to take a look at official page instructions :
postgressapp.com/documentation/remove.html
I had this same issue and mine was caused by some configuration issues I was having. Clearing the user configurations and reinstalling postgres in brew worked for me!
brew uninstall postgresql
rm -rf /usr/local/var/postgres
I ran the following:
psql --version then brew services stop postgresql#<VERSION>
finally, start your Postgres app on your Mac.

Resources