9

I have a Mac running OS X 10.6.8, which comes pre-installed with SQLite3 v3.6. I installed v3.8 using homebrew. But when I type "sqlite3" in my terminal it continues to run the old pre-installed version. Any help?

Not sure if PATH variable has anything to do with it, but running echo $PATH results in the following: /usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

And the NEW version of SQLite3 is in the following directory: /usr/local/Cellar/sqlite

I should add that I also downloaded the binary executable to my desktop, and that works if I click from my desktop, but doesn't work from the terminal.

Any help would be greatly appreciated?

2

$PATH

Yes you need to set your PATH variable like so:

$ export PATH=/usr/local/Cellar/sqlite:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

That line can be a bit tricky to read so here it is split up by the colons, and each path is on its own line:

$ awk -v addPath="$1" 'BEGIN{RS=":";ORS=addPath "\n"}{$1=$1}1' <<< $PATH
/usr/local/Cellar/sqlite
/usr/local/bin
/Library/Frameworks/Python.framework/Versions/2.7/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/usr/X11/bin

The $PATH is a list of directories - separated by colons (:) - which the shell searches through one by one looking for what ever you just typed at the prompt. The order matters so if sqlite shows up in multiple locations the first directory where it's found is where it will get used from.

where are things located?

You can use the type command to see where a particular application is coming from.

Examples

$ type -a sqlite3 
sqlite3 is /usr/bin/sqlite3

Here's I'm using it with the -a switch which will show all occurrences:

$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
  • That worked! Thank you so much. I didn't know how to add multiple paths into the statement. Now it's clear they're just separated by ":" – BandfuzzAlex Sep 5 '13 at 1:38
  • @user46531 - glad your issue was resolved. Thanks for the question. – slm Sep 5 '13 at 1:47
  • @user46531 while workable, this is the incorrect solution. see my answer. – strugee Sep 5 '13 at 6:45
11

slm's solution is actually incorrect (while usable). When using Homebrew you should not add /usr/local/Cellar/* into your $PATH; instead what you should do is you should add /usr/local/bin into your $PATH (which you have already done) and then symlink things in the Cellar into /usr/local/bin. Since it's designed this way, Homebrew can obviously do this pretty easily for you:

brew link sqlite

will automagically create the needed links. (Homebrew didn't do this automatically for you this time because sqlite is keg-only, meaning that you need to do it manually).

As a side note/friendly reminder, you should never add /usr/local/bin to the system path, only your user path. This is in case programs expect the Apple-provided sqlite but find the Homebrew-provided version, causing problems.

  • 1
    Possibly not a good idea. brew link sqlite: "Warning: sqlite is keg-only and must be linked with --force" – Marcelo Cantos Oct 6 '16 at 21:06
  • Yeah—what are the negative consequences (if any) of linking it forcibly? What could break? They really should give some indication of that in the warning message. – iconoclast Sep 24 '18 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.