Skip to content

Instantly share code, notes, and snippets.

@RobertoC27
Last active January 22, 2021 00:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save RobertoC27/5758e1f7f40185284bb669e8728b766f to your computer and use it in GitHub Desktop.
Save RobertoC27/5758e1f7f40185284bb669e8728b766f to your computer and use it in GitHub Desktop.
Setup Windows Subsystem for Linux (WSL) using Ubuntu 18.04 LTS, to do DApp development (web + blockchain)

Installation tips for using Windows Subsystem for Linux (WSL) using Ubuntu 18.04 LTS

and also setting up to do some blockchain development

Preparing for web development using WSL, I have taken from other sources and condensed it to save some time. This intends to be a quick setup guide, if you want and in-depth explanation go ahead and open the links at the bottom. I do not intend to take credit from them, links will be at the bottom.

How to enable this feature

  1. Go into "Turn Windows features on or off" and scroll down to Windows Subsystem for Linux and check the box. You will need to restart your PC
  2. Go to the windows store and search for 'ubuntu' select and install Ubuntu 18.04 LTS
  3. Now when you search for 'ubuntu' you will be able to launch a new bash terminal
  4. Setup your username and password

Before anything else update your packages

  1. sudo apt-get update
  2. sudo apt-get upgrade

Nodejs (v11.x)

  1. sudo apt-get install build-essential
  2. curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
  3. sudo apt-get install -y nodejs

Check your installation by running

node -v npm -v

Installing Yarn package manager (optional)

  1. curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  2. echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  3. sudo apt-get update && sudo apt-get install yarn optional. If you are gonna use global packages run export PATH="$(yarn global bin):$PATH" to ensure being able to access them

Restart your terminal now (might not be needed, but I like to do it)

To avoid typing the full path to your working directory, there are 2 options:

Choose the one that you like the most, just one of these is needed

1. Setting up a symbolic link

This is useful to avoid entering your Windows path every time

  1. ln -s /mnt/c/Users/<Insert your username>/<Your folder>/ ~/dev So it looks something like this ln -s /mnt/c/Users/roberto/Development/ ~/dev

2. Modify your ~/.profile file

  1. cd ~
  2. nano .profile
  3. navigate to the bottom of your file and paste the following:
# This allows you to switch between the Ubuntu root and your Windows Root.

# wr evaluates to the absolute path to your Windows user's root.
export wr=~/../../mnt/c/Users/<Windows Username>/<Working Folder>/

# This gives us a quick way of moving directly to the Windows root
alias cdwr='cd "$wr"'

# This brings you to your Windows Working directory immediatly when you open a new terminal.
cdwr
  1. Close and save the file
  2. Restart your terminal and you should be at your root folder

Asumming you have VSCode already installed Remember that since VSCode requires a GUI, you must install it through Windows Open a new terminal and run code . This will open a VSCode windows inside your working directory. You are now ready to start doing npm init or yarn init

I almost forgot setup VSCode to use WSL as default terminal.

  1. Open VSCode
  2. Open the command palette ctrl + shift + p
  3. Type default shell
  4. Select WSL Bash

create-react-app

The easiest way of starting a react project IMO. And now it doesn't need to be installed manually. yarn create react-app <project-name> npm init react-app <project-name>

Installing truffle

It may be done using yarn or npm yarn global add truffle npm i -g truffle

Errors during package installation

If during installation you get an error similiar to this one error An unexpected error occurred: "ENOENT: no such file or directory, lstat '/home/roberto/.cache/yarn/v4/npm-thunky-1.0.3-f5df732453407b09191dae73e2a8cc73f381a826/node_modules/thunky/LICENSE'". Is it a known issue here and here Retrying to install the library that caused the error sometimes fixes it. If after several retries you still cannot get it to work, try running rm -rf node_modules && yarn cache clean && yarn install <libray-name> or yarn cache clean && yarn install <libray-name>

Choosing a compiler version Since Truffle comes with a packaged compiler (0.5.0) and open zeppelin's contracts require other (0.5.2), the fix is to edit the truffle-config file and set the compiler version to 0.5.2, but also install it since it fails to get while using the config file. sudo truffle obtain --solc=0.5.2 will do the trick. Fixed with truffle ^0.5.8

Ganache

It's a bit of a special case Ganache, since WSL can connect to your Windows machine you can install it on either filesystem. If you'd like to have a GUI, then go for the Windows installer, but if you wanna feel more like a hacker you could go for the cli version on WSL.

Links I told you about

  1. In-depth guide
  2. Awesome medium article
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment