How to install Truffle & TestRPC on Ubuntu or Windows 10 with “Windows subsystem for Linux”
I previously wrote how you can install Truffle & TestRPC on a windows machine, by using the Windows installers for Node & npm.
However I have found it is a much nicer experience to use the Windows Subsystem for Linux which provides a native Ubuntu shell with bash, which allows me to run all the Linux tools natively without issues. These install steps will work on an Ubuntu machine as well.
Prerequisite if running on Windows
- Enable Windows subsystem for Linux and install from Windows Store.Follow this short guide on how to enable it https://msdn.microsoft.com/en-us/commandline/wsl/install_guide
- After following the steps in the guide above. Simply start the Ubuntu bash shell
Install steps
[BEST] Option 1: Clean install on a machine without node
# Make sure Ubuntu is up to date
sudo apt-get update -y && sudo apt-get upgrade -y
# Install build essentials & python. lots of NPM libraries require these
sudo apt install build-essential python -y# install nvm https://github.com/creationix/nvm#install-script (the below command is a single line)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash# restart bash to enable nvm (saves you restarting your terminal)
exec bash# install node and our npm packages
nvm install node
npm install -g truffle ganache-cli
Option 2: Node is already installed by other means, this will force update node to the latest version
# Install the dist-upgrade package and run it to update to the latest node version
sudo npm -g install dist-upgrade
sudo dist-upgradenpm install -g truffle ganache-cli
now you should be able to create a folder, go into it and run `truffle init` to create a new project template.
How to access your C: drive
WSL automatically mounts your drives under \mnt\. For example you can access c: by typing cd \mnt\c
I recommend putting your source code in c:/source/myproject, editing the code in VS Code, and then using the tools inside WSL by navigating to it e.g. cd /mnt/c/source/myproject
then you can run commands like truffle unbox
, truffle compile
Additional things to do
Now that your machine has it installed, I recommend you follow my other guide to get Visual Studio code configured for Truffle development.