Ethereum: Setting up a development environment

Update 16 Feb 2019: There is now an updated version of this article with Ubuntu 18, Truffle, and Ganache.

This article is a quick-start guide to setting up a Ethereum development environment. This setup can be used to develop smart contracts for both public and private blockchains. To facilitate rapid development we’ll be using ethereumjs-testrpc running in Ubuntu, and truffle to manage our projects, testing, compiling, and migration.

ethereumjs-testrpc is a Node.js based Ethereum client for testing and development. Read more about it here:

truffle is a development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier. Read more about it here:

For those running Windows (like myself), one of my previous articles steps through running Ubuntu on Windows 10 Pro using VirtualBox. I’ve used a similar environment for the steps in this article.

Install Nodejs

We want to make sure we get the latest v7 to ensure we can run testrpc

sudo apt-get update

sudo apt install curl

curl -sL | sudo -E bash -

sudo apt-get install -y nodejs

sudo apt-get install npm

Install ethereumjs-testrpc

Refer to

sudo apt-get install build-essential

sudo apt-get install git

sudo npm install -g ethereumjs-testrpc

Now run testrpc


Create a new nodejs project using Web3

  1. Open a new terminal window, and create a new folder then cd into it

    mkdir dapp && cd dapp
  2. Create pacakge.json file

    vi package.json
  3. Now hit i to go into insert mode, and type the following

      "dependencies": {
        "web3": "0.17.0-alpha"

    This is declaring web3 as a dependency, which we’ll install using npm in a moment.

  4. To save and exit, hit esc, then : and type wq, then hit enter

  5. Use npm to install web3. Type the below in the same folder as the package.json

    npm install
  6. Finally, we need to verify that everything is working. Ensure testrpc is still running in the other terminal. Now launch the node console

  7. Inside the node console, enter the following

    > var Web3 = require("web3")
    > var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
    > web3.eth.accounts

    This should return a list of accounts that matches those displayed in the testrpc window.

Install truffle and create a new project

  1. Install truffle. Note this takes a few minutes to complete.

    sudo npm install -g truffle
  2. We should be in the dapp folder created previously. If not, cd into it. Now create another folder for the truffle project and cd into it.

    mkdir project && cd project
  3. Run truffle init to generate a new truffle app

    truffle init

    This creates some new folders and files:

    • contracts
    • migrations
    • test
    • truffle.js

Explore truffle

Truffle gives us access to the power of Web3. Following the previous example of printing the testrpc accounts, we can do the same in truffle:

truffle console

Example output:

[ '0x5964af18b6226d04f262c1b0f5723642c8fae725',
'0x046e6441d76ee3e675cf2e2eeb5b0682b8d47b09' ]

Wrapping up

This is where we wrap up for now. Truffle includes some example smart contracts that you can compile and play with using testrpc, or you can try writing your own.

truffle compile
truffle migrate