24

I had the sqlite3 package installed on Ubuntu and there's no support for readline. That means there's no command history and those other nifty features readline gives you.

Is this a configuration or a packaging problem? Is there a different package archive somewhere that would give me readline support out of the box? Or else, how do I compile sqlite3 myself making sure it has readline support?

agentofuser
  • 7,677

4 Answers4

41

You could always use rlwrap:

rlwrap sqlite3 database.db

FYI, I just checked my hardy heron install, and its sqlite3 does have readline support.

Rudedog
  • 1,880
26

I add another answer because this is the first hit for "ubuntu sqlite3 readline" on google:

The android SDK installs its own version of the sqlite3 binary. This binary does not provide readline support. If you added the Android SDK to your path this might make you think you have no readline support, in fact every Ubuntu package is compiled with readline support.

Also see this Ubuntu Bug Report which describes the same situation.

theomega
  • 1,154
8
  1. Download the zip file containing C source code from https://www.sqlite.org/download.html (sqlite-amalgamation-nnnnnnn.zip)
  2. Unzip it to get shell.c, sqlite3.c, and the .h files.
  3. If not already installed, install libreadline and libncurses. On Ubuntu Linux, install by running the command below:

    sudo apt install libreadline-dev libncurses-dev

  4. Run the command below to build:

    gcc -DSQLITE_ENABLE_FTS5 -DHAVE_READLINE shell.c sqlite3.c -lpthread -ldl -lm -lreadline -lncurses -o sqlite3

Note: You need -DHAVE_READLINE and -lreadline and -lncurses to get readline functionality.

Copy the sqlite3 binary to /usr/bin or add to your path.

1

I managed to compile my own binary with this:

Download the "autoconf" source file from SQLite Download page. Unzip and extract the tar, change to source directory.

Compile the source code with:

./configure --enable-readline
make

I am running on RedHat, so I had to run yum install readline-devel beforehand. This might be different on your machine.