Set up your development environment for Ethereum on a Linux machine


In this lecture, we are going to set up
our development environment for Linux with all the tools that are required to
develop smart contracts for Ethereum. We’re not going to describe all of them
but focus on those that are widely used by the community. By the way, this lecture
is specifically for Linux. If you are running on Windows or MacOS, there are
dedicated lectures for that. So our toolbox will be composed of the
following tools: Geth, Ganache, Truffle and Atom. Let’s start with Geth. Geth or Go-Ethereum is the command line interface that allows you to run and operate a
full Ethereum node. Geth is implemented in Go and allows you to mine blocks, to
generate Ether, to deploy and interact with smart contracts, to transfer funds,
to inspect block history, to create accounts, and so on and so forth. Geth can
be used to connect to the public Ethereum network, also called main net, or to
create your own private network for development purposes, which we will
demonstrate later in this course. The benefit of using Geth in your
development process is to let you fully test your application before deploying
it to the main net. The exact procedure to install Geth might depend on your
exact Linux distribution. More information is available at the
following location. By the way, this link and all the other links that we
mention in this video and all the other videos will be in the resources of
each lecture. On Ubuntu, which is the distribution we are using here, now in
the terminal I can use the following commands to install everything. So first
of all “sudo apt install software-properties-common” OK so I already
have the latest version installed, that’s good. Now I need to add the repository
for Ethereum, so “sudo add-apt-repository -y ppa:ethereum/ethereum” OK, and now I can do “sudo apt update” to update the
repositories. And last but at least “sudo apt install ethereum”. I confirm the changes,
and once those commands completed successfully, you can check the version
that is installed by running “geth version”. And here you can see I have 1.7.3-stable
which is the latest version at the time of this recording. Ok so Geth is installed
now. The second tool that we’ll install is Ganache.
Now Ganache is an Ethereum blockchain emulator that you can use for
development purposes. Ganache can be seen as a replacement for TestRPC, which we
used in previous versions of this course. The strength of Ganache is its UI, that
allows you to inspect blocks and transactions in a more user-friendly way.
Compared to Geth, Ganache is an in-memory Ethereum node, that runs faster and
provides all the visual components you need to test your contracts locally
before deploying them to a real Ethereum implementation. To install
Ganache, we can go to the browser: “truffleframework.com/ganache”
and here, it will detect that I’m on Linux and offer to download the Linux
package. So here, this button made me download an AppImage package. So I’m
just gonna show it in folder, right click it… Properties… Permissions… “Allow
executing file as a program”. So I’m just making this file executable. And now I
can double click it. “Would you like to integrate Ganache with your system?” Yes,
please. And then it starts Ganache. So first of
all, I will accept Analytics, and this is the main interface for Ganache. Let me
close everything around it so that we can see more clearly.
Ok so let’s quickly review the main features of Ganache. When you start
Ganache it starts a new Ethereum node in memory, on network identifier 5777, which we can see here, in this part of the screen. And it also
creates ten accounts and puts a hundred ethers on each account. Now contrary to
what happened with TestRPC, Ganache always creates the same accounts and
uses the same mnemonic, so it’s deterministic, which is very practical
when we will need to import all those accounts later on in Metamask. So the
first screen you see is the “Accounts” view, and here at the top of the screen,
you can see the current block, which is the number of the last block mined by
the node. You can see the gas price, which is the minimum gas price this node
requires on transactions in order to mine them. Gas limit is the maximum gas
this node is willing to accept per block. The network identifier you can see here.
RPC server corresponds to the host and port of the RPC endpoints that this
node is listening to. And the mining status is also important because, by
default, this fake node only mines a new block when it receives a new transaction,
which is completely different from what a real node would do, since a normal node
would mine a new block at regular intervals, whether there are pending
transactions or not. We’ll come back to that later. You can disable auto-mining,
come back to a more normal behaviour, and even set a mining block time in the
settings. We’ll see that in a moment. And here we also have the mnemonic, which is
the seed words that are used to generate the wallets of the ten accounts in a
deterministic way. Then you can see a list of the 10 accounts generated by
Ganache, with the following information: the wallet address of the account, its
balance in ether with only two decimals, the number of
transactions already sent by this account since the node started, the index
of the account in the list of accounts, and the private key button that makes it
possible for you to see the private key for each account, which will be very
practical when we import the accounts in Metamask. The second tab is the “Blocks”
tab, and it shows a list of all the blocks mined by this node. And for now,
when we launch, there’s only one block, the genesis block, and it doesn’t contain
any transaction. We also have the “Transactions” tab, where we will be able
to see a list of transactions. For now there is none. And in the “Logs”
tab, we can see the console output for the running node. We also have a search
field, where we can search blocks and transactions by numbers and hashes. And
finally, we have the “Settings” button, where we can customize the configuration
of Ganache. So we can change the hostname, the port number and the network
identifier. We’ll actually do that a lot later on. We can also deactivate auto-mining, and set a mining block time. In our case we’ll leave auto-mining on. We
can also customize the number of accounts that are generated when Ganache starts
and change the mnemonic. Here we’ll leave it as default. In the “Chain” part, we
can change the gas limit and the gas price. And in “Advanced”, we can
enable/disable Google Analytics. Remember that every time you change
something in the settings, you need to save and restart. Here we’ll just cancel
and we’ll leave Ganache. The next things we need to install are NodeJS and NPM.
NodeJS is a server-side JavaScript platform to create applications that
will interact with our Ethereum node. When we install NodeJS, we also install Node Package Manager, or NPM, that is required to set up most of the tools and
libraries required to develop for Ethereum. To check if NodeJS and NPM are
already installed on your machine, you can use the following commands in the
terminal: “node -v” and “npm -v” Here I don’t have any version
already installed. If you have already NodeJS or NPM, check that your NodeJS is at
least version 8, and NPM is at least version 5, otherwise you will need to
upgrade them, or remove your current installation, and install node.js again
from scratch. The procedure to do that might depend on your exact Linux
distribution and the version of NodeJS that’s already installed. Google is your
best friend here. If NodeJS is not already installed on your system, NodeJS
can be installed in different ways. We are going to follow the procedure
specified on the NodeJS website, so we can go to the browser and open “nodejs.org”, go to “Downloads”, and at the bottom, we can see “installing NodeJS via
package manager”. We’re gonna go there and then click on whatever Linux
distribution we’re using, and here we are using a “Debian and Ubuntu based Linux
distribution” so this procedure will use curl, and I’m not sure
that it’s already installed, so I’m going back to the terminal, and run “sudo apt
install curl”. OK, so now curl is installed. I can go back to the website
and copy the command that is most adapted. In our case, we want to install
NodeJS 9, so I will copy this command, and this will simply add the repository to
APT. Now that is there, I can run “sudo apt install -y nodejs”. Now if
you can see, on the website, they also recommend to install the build tools
that are going to be important to install certain NPM packages. So also
copy that, and run it in our terminal. And I already have the latest version, which
is good. So now that this is done, if I type “node -v”, I should see the latest version. And “npm -v” should show me the
5.5.1 version. Next thing we need to set up is Truffle 4. To compile,
test and deploy your smart contracts, you will need a build framework that will
increase your development velocity compared to doing it manually, and we’ll
demonstrate that fact later in this course. In this context, we are going to
use Truffle 4, as opposed to Truffle 3, that we used in previous versions
of this course, and you can find more information about it on “truffleframework.com”… Actually, as you can see, it’s installed
as an NPM package, so we can go back to the Terminal and run NPM. So the first
thing we need to do is to uninstall previous versions of Truffle. This is
important: if you already have Truffle version 3 or below, you definitely need
to uninstall them first. So to do that you run “npm uninstall -g truffle”. And
once this is done, we use “npm install -g”… but we won’t install just the latest
version of Truffle, we will focus on 4.0.4. This is to avoid any breaking change in
newer versions that might not work with this course content. So here I can see
that I have missing right access, and that’s normal because I completely
forgot that on Linux, we need to run these commands with sudo. And now that it
is done I can run “truffle version” to check that 4.0.4 is installed, and version
0.4.18 of the Solidity compiler is also set up. The last step of this
lecture is to install a text editor that we’ll use to edit our smart contracts
and other text files. At this point in time, there is no real Ethereum IDE. You
can find some plugins for IntelliJ, WebStorm,
or even Microsoft Visual Studio Code, but not a full IDE covering all the
development chain. But that’s ok, because we have some interesting free text
editors that are good enough for what we want to show here. In this course, we
chose to use Atom because it’s freely available for Mac, Windows and Linux. But
of course, you are free to use the one that you are more familiar with. To
install Atom, we can go to the Github repository: “github.com/atom/atom”. Again the link will be in the resources, and then we can go to “Releases”.
And there you can choose not the beta package, but the latest stable release so
here it would be 1.23.2. If you are on Ubuntu or a Debian distribution, which is
our case, you can also also install it from the Terminal. Then I can run “sudo
apt update” and finally “sudo apt install atom” So here normally we installed Atom
and APM as well, which is the Atom Package Manager. We can actually start
Atom to make sure that the environment is initialized. And finally we can run “apm install language-ethereum” to install the plugin in Atom to support the Solidity
language, which we will use to write our smart contracts later on. So at this
stage, we have all the tools that we need to start the development of our smart
contracts on Linux. In the next lecture, we’ll show you how to create, set up and
start your own private Ethereum node.

8 thoughts on “Set up your development environment for Ethereum on a Linux machine”

  1. just so u know, this only work on ubuntu if u are using debian then please follow this solution: https://gist.github.com/drandreaskrueger/912e704cfc86fd757277a5fd9bd372d4

  2. I've downloaded the Ganache from https://truffleframework.com/ganache and gave permission to run as program but it's not running. its doing nothing

  3. I’ve been working through a Truffle and Ganache install all day.

    Nothing has mentioned Geth yet.
    I can’t wait to try this.

  4. I'm watching this in August 2019, and at the current time of my writing this comment, the site to download Ganache right now is actually:
    https://www.trufflesuite.com/ganache
    and the site for the Truffle framework is:
    https://www.trufflesuite.com/truffle

    Thank you so much for making this video. You've been an absolute lifesaver <3

Leave a Reply

Your email address will not be published. Required fields are marked *