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
- 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
- Go to the windows store and search for 'ubuntu' select and install Ubuntu 18.04 LTS
- Now when you search for 'ubuntu' you will be able to launch a new bash terminal
- Setup your username and password
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs
Check your installation by running
node -v
npm -v
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
optional. If you are gonna use global packages runexport 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)
Choose the one that you like the most, just one of these is needed
This is useful to avoid entering your Windows path every time
ln -s /mnt/c/Users/<Insert your username>/<Your folder>/ ~/dev
So it looks something like thisln -s /mnt/c/Users/roberto/Development/ ~/dev
cd ~
nano .profile
- 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
- Close and save the file
- 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.
- Open VSCode
- Open the command palette
ctrl + shift + p
- Type default shell
- Select WSL Bash
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>
It may be done using yarn or npm
yarn global add truffle
npm i -g truffle
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. Fixed with truffle ^0.5.8 sudo truffle obtain --solc=0.5.2
will do the trick.
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.