databases

How to Download and Install SQLite

Open your terminal and run this command:

sqlite3 terminal command

If by any reason you don't have it installed. It's simple to install.

  1. Visit the downloads page.
  2. Download sqlite-autoconf-XXXXXXX.tar.gz.
  3. Run the following commands from your terminal window:

cd ~/Downloads #or where you saved the tar file.
tar xvfz sqlite-autoconf-XXXXXX.tar.gz
cd sqlite-autoconf-XXXXXXX
./configure --prefix=/usr/local
make
make install

Remember to replace sqlite-autoconf-XXXXXXX with your file. It should look something like sqlite-autoconf-3350200. (This was the file at the time of this post.)

Installing SQLite with Homebrew

If you're already familiar with Homebrew and have it installed, then you can just run this command:

brew install sqlite3

Creating your first database

  1. Open the terminal and type sqlite3 cars.db
  2. Then run the statements below:
sqlite3 terminal database creation example

If you want to copy and paste the code, here it is:

create table favorite_cars(Year integer, Make varchar, Model varchar);
insert into favorite_cars values(2003,"BMW","M3");
select * from favorite_cars;

Your database will be created in the folder path that you ran the sqlite3 cars.db command.

In my case this is where it was created:

database file path