Install sqlite3 on mac osx?

2019-01-20 01:05发布

问题:

I just bought a new MBP

I've read online Sqlite3 already exists on OSX.

I've downloaded mac ports (and installed it) as well as the bin file for sqlite3 from the official web site.

In a guide I'm reading about rails, which tells me to update sqlite3, I run the following in terminal: sudo port upgrade sqlite3

I receive the following error: Error: sqlite3 is not installed

I am so lost! Please help

回答1:

It's not installed via mac ports, so port doesn't know about it. You could either do an install via port or get rails to use the one that's installed on the Mac already.



回答2:

I don't remember the default configuration, but like you i installed sqlite myself. You can check your sqlite installation is complete by typing using the which command in the OS X terminal:

$ which sqlite3
/opt/local/bin/sqlite3

If which doesn't reveal anything, then sqlite3 isn't in your system's PATH. Use the cat command to see how that's set up (in your /etc/profile file;)

$ cat /etc/profile
# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi


export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export PATH="/usr/local/mysql/bin:$PATH"
export PATH="/opt/svn/subversion-1.4.3/bin:$PATH"
export PATH="/opt/ruby/bin:$PATH"
export PATH="/opt/sqlite/bin:$PATH"

You can open that file in a text editor and add the path to the lines at the bottom. You can see I've installed sqlite to /opt/sqlite, not /usr/local, so i've had to add that to my path. This tells the system to check there for executable files when a command is given.

Once that's done you need to ensure that Ruby has the functionality it needs to interact with sqlite. We do that by installing the sqlite3 gem. Maybe you don't need to:

$ sudo gem list
Password:

*** LOCAL GEMS ***

# ...loads of gems listed ...

sqlite3-ruby (1.2.4)

# ... loads of gems listed ...

If it's not there, `sudo gem install sqlite3-ruby' will sort you out in no time. Rails should work with sqlite out of the box if you take those two steps.



回答3:

To install the sqlite gem the binary won't be enough afaik. You'll need the amalgamation tarball from the sqlite website or install it via ports:

sudo port install sqlite3 


回答4:

I've seen many posts that recommend you install XCode Tools. I already had XCode 3.2 Installed. Installing XCode from the CD didn't help.

What did help is the following:

sudo env ARCHFLAGS="-arch x86_64" gem install sqlite3-ruby

I believe the "env ..." statement will also help if you're trying to install mysql on Snow Leopard.