Databases with SQLite

SQLite Installation

First we have to get SQLite installed on your computer.

Go to SQLite and click the 'Download' button.

This brings you to another page with several options. Choose the appropriate file for your OS. I chose 'Precompiled Binaries for Mac OS X (x86)'.

That will download a .zip file to your Downloads directory.

Now in Finder (macOS), double-click that .zip file. This will create a new directory and extract some files into it:

  • sqlite3
  • sqlite3_rsync
  • sqlite3_analyzer
  • sqldiff

    In order to be able to use any of these files, they have to be in a directory that is in your path.

    I typically create a 'bin' directory in my 'Home' directory, and put that in my path ($PATH). If you don't already have a bin directory in your Home directory, here's how:

    mkdir -m 0755 ~/bin
    

    That will create a new directory bin in your Home directory and allow it to run scripts.

    Any scripts that you create should be in this directory.

    It's also where you can copy the sqlite3 (and the others if you wish) file you just downloaded.

    Now we need to tell bash (the shell) to look in your bin directory for commands and scripts.

    echo PATH=$PATH":/Users/`whoami`/bin" >> ~/.bash_profile
    

    Paste that command into Terminal - those are NOT apostrophes around whoami, but back-ticks.

    This will add the new bin directory to a special file in your Home directory (.bash_profile).

    Whenever you make changes to the .bash_profile file, you MUST close and quit Terminal, then restart it again

    Do that now.

    To verify you've done that right, enter the following in Terminal:

    echo $PATH
    

    You should see a long list of stuff, with the newest directory tacked on the end.

    Congratulations!


    Now we also need a place to put the database file/s when created.

    Using the same method, create a directory in your Home directory. You can use whatever name makes sense to you. Recall if the name you use has spaces, it must be wrapped in double-quotes.

    mkdir -m 0755 ~/MyDB
    

    How hard was that?

    You should now be ready to run SQLite completely. Now the fun begins.

    DB Pre-conditions