Installing bitcoin on Debian ‘squeeze’

Instead of being outdoors I geeked out indoors this weekend and amongst other things installed a Bitcoin daemon on a public facing server so I could have a play with the API/RPC features.

Below I document the steps I followed as it turned out to be slightly more taxing than the usual apt-get install bitcoind

Step 1) Get server

This is obviously optional depending on where it’s going but as I wanted it on a public facing machine and I’ve got a few projects where I need to using it soon I installed a new Debian image on the Rackspace cloud.

The newest version of Debian is ‘squeeze’ so I chose that and as for now this is for testing I chose the cheapest instance, 256MB RAM/10GB space for 24p a day (!) but can change this later if I need more grunt.

Step 2) apt-get install fail

It turns out that bitcoind isn’t in the standard package list for squeeze so you need to install it via back-ports. To do so add the following to your /etc/apt/sources.list

deb squeeze-backports main contrib
 deb-src squeeze-backports main contrib

Save, then run:

apt-get update
apt-get install bitcoind

Step 3 ) Install start-up & config scripts

Again, surprisingly for a debian package, there’s no start-up or config installed for you. So you’re going to have to do it yourself.

I took the

script found on this forum and edited it as per the thread recommendations with a few tiny mods of my own:

#! /bin/sh
# Provides:          bitcoind
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: bitcoind daemon startup script
# Description:       bitcoind daemon startup script

# Author: Pavel A. Karoukin

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the script
DESC="BitCoin Daemon"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Function that starts the daemon/service
   # Return
   #   0 if daemon has been started
   #   1 if daemon was already running
   #   2 if daemon could not be started
   start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null 
      || return 1
   start-stop-daemon --start --quiet --chuid $CHUID --pidfile $PIDFILE --exec $DAEMON -- 
      || return 2

# Function that stops the daemon/serv
   # Return
   #   0 if daemon has been stopped
   #   1 if daemon was already stopped
   #   2 if daemon could not be stopped
   #   other if a failure occurred
   $DAEMON stop
   start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME

   [ "$RETVAL" = 2 ] && return 2
   # Wait for children to finish too if this is a daemon that forks
   # and if the daemon is only ever run from this initscript.
   # If the above conditions are not satisfied then add some other code
   # that waits for the process to drop all resources that could be
   # needed by services started subsequently.  A last resort is to
   # sleep for some time.
   start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
   [ "$?" = 2 ] && return 2
   # Many  daemons don't delete their pidfiles when they exit.
   rm -f $PIDFILE
   return "$RETVAL"

# Function that sends a SIGHUP to the daemon/service
do_reload() {
   # If the daemon can reload its configuration without
   # restarting (for example, when it is sent a SIGHUP),
   # then implement that here.
   start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
   return 0

case "$1" in
   [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
   case "$?" in
      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
   [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
   case "$?" in
      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
   # If do_reload() is not implemented then leave this commented out
   # and leave 'force-reload' as an alias for 'restart'.
   #log_daemon_msg "Reloading $DESC" "$NAME"
   #log_end_msg $?
   # If the "reload" option is implemented then remove the
   # 'force-reload' alias
   log_daemon_msg "Restarting $DESC" "$NAME"
   case "$?" in
      case "$?" in
         0) log_end_msg 0 ;;
         1) log_end_msg 1 ;; # Old process is still running
         *) log_end_msg 1 ;; # Failed to start
        # Failed to stop
      log_end_msg 1
   #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
   echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
   exit 3


Note: items in the script above that may (or will definitely) need changing depending upon your environment are in bold.

Save it as /etc/init.d/bitcoind then run:

chmod +x /etc/init.d/bitcoind
update-rc.d bitcoind defaults

Now you need a config file, I got an example one here. Paste it into /home/[user script will run as]/.bitcoin/bitcoin.conf

# bitcoin.conf configuration file. Lines beginning with # are comments.
# Network-related settings:
# Run on the test network instead of the real bitcoin network.
# Connect via a socks4 proxy
# Use as many addnode= settings as you like to connect to specific peers
# . or use as many connect= settings as you like to connect ONLY
# to specific peers:
# Do not use Internet Relay Chat ( #bitcoin channel) to
# find other peers.
# Maximum number of inbound+outbound connections.
# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)
# server=1 tells Bitcoin to accept JSON-RPC commands.
# You must set rpcuser and rpcpassword to secure the JSON-RPC api
# How many seconds bitcoin will wait for a complete RPC HTTP request.
# after the HTTP connection is established.
# By default, only RPC connections from localhost are allowed. Specify
# as many rpcallowip= settings as you like to allow connections from
# other hosts (and you may use * as a wildcard character):
# Listen for RPC connections on this TCP port:
# You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind
# running on another host using this option:
# Use Secure Sockets Layer (also known as TLS or HTTPS) to communicate
# with Bitcoin -server or bitcoind
# OpenSSL settings used when rpcssl=1
# Miscellaneous options
# Set gen=1 to attempt to generate bitcoins
# Use SSE instructions to try to generate bitcoins faster. For muliple core processors.
# Pre-generate this many public/private key pairs, so wallet backups will be valid for
# both prior transactions and several dozen future transactions.
# Pay an optional transaction fee every time you send bitcoins. Transactions with fees
# are more likely than free transactions to be included in generated blocks, so may
# be validated sooner.
# Allow direct connections for the .pay via IP address. feature.
# User interface options
# Start Bitcoin minimized
# Minimize to the system tray

4) Run

You can just run the init.d script now, but to be 100% sure that it’ll start on boot I simply rebooted.

On startup I could see a bitcoind process running and in my ~/.bitcoin/ folder I ran

watch ls -alh

I could see these two files slowly increasing in size, as the complete block chain was being synchronised:

-rw------- 1 bealers bealers 151M Jan 22 10:36 blk0001.dat
-rw------- 1 bealers bealers 90M Jan 22 10:36 blkindex.dat

You can get more info by running:

bitcoind getinfo
 "version" : 32400,
 "balance" : 0.00000000,
 "blocks" : 135450,
 "connections" : 114,
 "proxy" : "",
 "generate" : false,
 "genproclimit" : -1,
 "difficulty" : 1563027.99611622,
 "hashespersec" : 0,
 "testnet" : false,
 "keypoololdest" : 1327245731,
 "paytxfee" : 0.00000000,
 "errors" : ""

From this I could see that blocks was under the current count.

  • If you would like to install a more recent version, you can get the latest stable from the bitcoin Ubuntu PPA by using:

    deb maverick main
    deb-src maverick main

    As far as i can tell right now, the required Squeeze libraries match the ones from Maverick.


  • Don’t you need to set this to ‘1’ ?

    > # Set gen=1 to attempt to generate bitcoins
    > gen=0

    • Panda

      > Don’t you need to set this to ’1′ ?

      Only if you are a miner. On a normal root server I would never set this to 1.

    • dude

      Only if you want to cpu-mine on the rackspace node, which would be a waste of resources.

  • Mark

    I was going to say the same thing …