This is a guide to installing CartoDB on Ubuntu 16.04, based on the CartoDB installation docs from Ubuntu 12.04.
Installations assume you use UTF8. You can set the locale by doing this:
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
In order to easily install some packages repositories sources is suggested to install this tool:
sudo apt-get install python-software-properties
Although we try to maintain packaged versions of almost every part of the stack, there are some parts like gems or npm packages that need some development tools in the system in order to compile. You can install all the needed build tools by doing this:
sudo apt-get install autoconf binutils-doc bison build-essential flex
You will need git commands in order to handle some repositories and install some dependencies:
sudo apt-get install git
The below is needed to get the latest version of GDAL
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
Install client packages
sudo apt-get install libpq5 \ libpq-dev \ postgresql-client-9.5 \ postgresql-client-common
Install server packages
sudo apt-get install postgresql-9.5 \ postgresql-contrib-9.5 \ postgresql-server-dev-9.5 \ postgresql-plpython-9.5
PostgreSQL access authorization is managed through pg_hba.conf configuration file, which is normally in /etc/postgresql/9.5/main/pg_hba.conf. Here it's defined how the users created in postgresql cluster can access the server. This involves several aspects like type of authentication (md5, no password, etc..) or source IP of the connection. In order to simplify the process of the installation we are going to allow connections with postgres user from localhost without authentication. Of course this can be configured in a different way at any moment but changes here should imply changes in database access configuration of CartoDB apps.
This is the pg_hba.conf with the no password access from localhost:
local all postgres trust local all all trust host all all 127.0.0.1/32 trust
For these changes to take effect, you'll need to restart postgres:
sudo service postgresql restart
Create some users in PostgreSQL. These users are used by some CartoDB apps internally
sudo createuser publicuser --no-createrole --no-createdb --no-superuser -U postgres sudo createuser tileuser --no-createrole --no-createdb --no-superuser -U postgres
Install CartoDB postgresql extension. This extension contains functions that are used by different parts of the CartoDB platform, included the Editor and the SQL and Maps API.
git clone https://github.com/CartoDB/cartodb-postgresql.git cd cartodb-postgresql git checkout <LATEST cartodb-postgresql tag> sudo make all install
Install Proj
sudo apt-get install proj-bin proj-data libproj-dev
Install JSON
sudo apt-get install libjson0 libjson0-dev python-simplejson
Install GEOS
sudo apt-get install libgeos-c1v5 libgeos-dev
Install GDAL
sudo apt-get install gdal-bin libgdal1-dev libgdal-dev sudo apt-get install gdal2.1-static-bin
Install PostGIS
sudo apt-get install libxml2-dev sudo apt-get install liblwgeom-2.2-5 postgis postgresql-9.5-postgis-2.2 postgresql-9.5-postgis-scripts
Initialize template postgis database. We create a template database in postgresql that will contain the postgis extension. This way, every time CartoDB creates a new user database it just clones this template database
sudo createdb -T template0 -O postgres -U postgres -E UTF8 template_postgis sudo createlang plpgsql -U postgres -d template_postgis psql -U postgres template_postgis -c 'CREATE EXTENSION postgis;CREATE EXTENSION postgis_topology;' sudo ldconfig
Run an installcheck to verify the database has been installed properly
sudo PGUSER=postgres make installcheck # to run tests
Check https://github.com/cartodb/cartodb-postgresql for further reference
Restart PostgreSQL after all this process
sudo service postgresql restart
Redis 3+ is needed.
Install redis
sudo apt-get install redis-server
Warning
By default redis server is configured to not have any type of disk persistence. If stopped or restarted everything stored in redis will be lost. In CartoDB redis is not just a simple cache storage. It stores information that need to be persisted.
Make sure to have proper values of save, appendonly and appendfsync config attributes. For more information check http://redis.io/topics/persistence
NodeJS is required by different parts of the stack. The more significant are the Maps and SQL APIs. It's also used to install and execute some dependencies of the editor.
Install NodeJS
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm nvm install 6.9.2
Note this should install both NodeJS 6.9.2 and npm 3.10.9. You can verify the installation went as expected with:
node -v npm -v
If npm version is wrong you should update it:
npm install npm@3.10.9 -g
We will also install some development libraries that will be necessary to build some Node modules:
sudo apt-get install libpixman-1-0 libpixman-1-dev sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev libpango1.0-dev
Lastly, the below is necessary for Phusion passenger to be able to find node
sudo ln -sf /home/ubuntu/.nvm/versions/node/v6.9.2/bin/node /usr/local/bin/node
Download API
git clone git://github.com/CartoDB/CartoDB-SQL-API.git cd CartoDB-SQL-API git checkout master
Install npm dependencies
npm install
Create configuration. The name of the filename of the configuration must be the same than the environment you are going to use to start the service. Let's assume it's development.
cp config/environments/development.js.example config/environments/development.js
Start the service. The second parameter is always the environment if the service. Remember to use the same you used in the configuration.
node app.js development
Download API
git clone git://github.com/CartoDB/Windshaft-cartodb.git cd Windshaft-cartodb git checkout master
Install npm dependencies
npm install
Create configuration. The name of the filename of the configuration must be the same than the environment you are going to use to start the service. Let's assume it's development.
cp config/environments/development.js.example config/environments/development.js
Start the service. The second parameter is always the environment of the service. Remember to use the same you used in the configuration.
node app.js development
Download ruby-install. Ruby-install is a script that makes ruby install easier. It's not needed to get ruby installed but it helps in the process.
wget -O ruby-install-0.5.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.5.0.tar.gz tar -xzvf ruby-install-0.5.0.tar.gz cd ruby-install-0.5.0/ sudo make install
Install some ruby dependencies
sudo apt-get install libreadline6-dev openssl
Install ruby 2.2.3. CartoDB has been deeply tested with Ruby 2.2.
sudo ruby-install ruby 2.2.3
Ruby-install will leave everything in /opt/rubies/ruby-2.2.3/bin. To be able to run ruby and gem later on, you'll need to add the Ruby 2.2.3 bin folder to your PATH variable. It's also a good idea to include this line in your bashrc so that it gets loaded on restart
export PATH=/opt/rubies/ruby-2.2.3/bin:$PATH
- Note that the above has to be added to BOTH your user and the root user .bashrc files.
Install bundler. Bundler is an app used to manage ruby dependencies. It is needed by CartoDB's editor
sudo su gem install bundler
Install compass. It will be needed later on by CartoDB's editor
sudo su gem install compass
Download the editor code
git clone --recursive https://github.com/CartoDB/cartodb.git cd cartodb
Install pip
sudo wget -O /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py sudo python /tmp/get-pip.py
Install a necessary package for python dependencies
sudo apt-get install python-all-dev
Install dependencies
sudo apt-get install imagemagick unp zip RAILS_ENV=development bundle install npm install sudo apt-get install libgdal-dev sudo pip install --no-use-wheel -r python_requirements.txt
Warning
If this fails due to the installation of the gdal package not finding Python.h or any other header file, you'll need to do this:
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
export PATH=$PATH:/usr/include/gdal
After this, re-run the pip install command. Variables can be passed to sudo if exporting them and re-running pip install
doesn't work:
sudo CPLUS_INCLUDE_PATH=/usr/include/gdal C_INCLUDE_PATH=/usr/include/gdal PATH=$PATH:/usr/include/gdal pip install --no-use-wheel -r python_requirements.txt
If gdal keeps failing, see more information here: http://gis.stackexchange.com/questions/28966/python-gdal-package-missing-header-file-when-installing-via-pip
Add the grunt command to the PATH
export PATH=$PATH:$PWD/node_modules/grunt-cli/bin
Install all necesary gems
bundle install
Install grunt-cli"
npm install -g grunt-cli
Precompile assets. Note that the last parameter is the environment used to run the application. It must be the same used in the Maps and SQL APIs
bundle exec grunt --environment development
Create configuration files
cp config/app_config.yml.sample config/app_config.yml cp config/database.yml.sample config/database.yml
Initialize the metadata database
RAILS_ENV=development bundle exec rake db:create RAILS_ENV=development bundle exec rake db:migrate
Start the redis-server that allows access to the SQL and Maps APIs:
redis-server &
Start the editor HTTP server
RAILS_ENV=development bundle exec rails server
In a different process/console start the resque process
RAILS_ENV=development bundle exec ./script/resque