DEV Community

rockiger
rockiger

Posted on • Originally published at rockiger.com

Windows Survival Guide for React and Web Developers

Introduction or why I wrote a survival guide

As a lifelong Linux user I started a job in a company where I had to use a Windows laptop. My job is to create a React frontend. Not knowing Windows I wondered about the best way to do my development work.

2 Routes

During my research I discovered two ways for emulating a Linux/macOS like workflow in Windows.

The first way creates a minimal bash environment to emulate a Linux command line. You will run Windows alternatives of your development tools.

The second route uses the Windows Subsystem for Linux 2 (or short WSL 2) to create a Linux environment inside your Windows system. This way you can use all your Linux tools like in your Linux distro. On the downside it uses more system resources and needs more work to set up.

Which route to choose?

If you have admin rights to your Windows machine and prefer Linux over Windows I would recommend going with WSL.

Fast Route

Pros:

  • easy to setup
  • doesn't need admin right
  • uses fewer resources

Cons:

  • it doesn't have to full power of a Linux distribution
  • your dev-environment will probably differ from your prod-environment
  • IO-operations with Yarn/NPM are slower

The fast route works fine for developers who want to get started quickly or don't have admin rights on their development machine. It will imitate a Linux or Mac dev-environment with a package manager for Windows called Scoop.

The apps we install later are selected because they work without admin rights. For that reason I opted to install Node.js directly instead of using nvm-windows which needs admin rights to set the default node version.

To start, open a PowerShell and install scoop first. Paste the following lines in your PowerShell:

set-ExecutionPolicy RemoteSigned -Scope currentUser
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
 # If you get an error 'https is not supported try typing it by hand. Windows screws up URLs.
scoop help
 # for usage information
scoop search # this will show all available packages
scoop search git # this will show all available packages with git in their name

Now that we installed scoop, we can install our dev-environment:

scoop install git
scoop install nodejs-lts
scoop install yarn

Now it's time to test our dev-environment. Assuming you come from a Bash background, it makes sense you are using Git Bash now, which was installed with git automatically. Open up Git Bash and create a React app:

git install https://github.com/GermaVinsmoke/bmi-calculator.git # If you get an error 'https is not supported try typing it by hand. Windows screws up URLs.
cd bmi-calculator.git
yarn # this will take some time
yarn start # this should start your default browser on http://localhost:3000

Bonus: Installing an editor

Assuming that you don't want to use notepad or vim for your development. It makes sense to install a different editor. Therefore we need to add another repository (called bucket) to scoop, then we can install most editors available (Atom, VScode, Notepad++).

For fans of Jetbrains products there is an additional bucket called jetbrains.

scoop bucket add extra
scoop install vscode # or notepadplusplus or atom

If you are using Git Bash it makes sense to restart it, because otherwise the editor will not available in your path. Other than that you are now good to go.

Rockstar Route

Pros:

  • dev-environment is the same as the prod-environment
  • has access to all Linux tools
  • very fast IO with NPM
  • can even run Linux GUI programs

Cons:

  • uses more system resources
  • needs more work to set up

Check if you have the right windows version

If you want to install WSL 2 you need Windows build 18917 or higher. You can check your Windows version with the shortcut Win+R and enter winver in the entry field. If you don't have a suitable build you need to join the Windows Insider Programm in your Settings. I recommend the Slow track, where you get updates about once a week.

Install WSL2

First, we need to enable the Windows Subsystem for Linux and enable the Virtual Machine Platform.

Open a PowerShell as administrator:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux # is this really needed
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart your system.

Install a Linux Distribution (Assumes that you install Ubuntu)

First set WSL 2 as default. In a PowerShell enter:

wsl --set-default-version 2

After that, go to the Microsoft Store and search for the Linux distro you like. I will assume you chose Ubuntu.

Open the Ubuntu from the Start menu and create a new user. The full installation of Ubuntu will need a view minutes.

When the installation has finished, update the packages.

sudo apt update && sudo apt upgrade

Now you have a fully functional Ubuntu at your fingertips. And can install your development tools analog to our solution above.

By the way, if you want to open your current Ubuntu directory in Windows just type:

explorer.exe .

An Explorer window will open on your screen.

Install VSCode on Windows

To develop comfortably on Windows you should install VSCode on Windows. I personally had problems with the Scoop version. So install the version from their website.

Similar to the file explorer you can then open Ubuntu directories with

code .

Install NodeJS and Yarn on Ubuntu

Open up an Ubuntu window and enter the following code to install Yarn

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 update && sudo apt install yarn

Then install NodeJS with Node Version Manager.

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.bashrc
nvm install --lts

Use Linux tools to develop

Now you should be able to use the development tools you need. To test your new environment try

npx create-react-app my-app
cd my-app
yarn start

A browser tab should open and you are able to start developing.

Which way to develop do you prefer? Let me know if you are interested running Linux GUI programs with WSL 2.

​​

Top comments (8)

Collapse
 
bitdweller profile image
Pedro Pimenta

I'm trying out Windows after 15+ years of being a mac-only user and dev. I tried linux but it still doesn't fit my needs, sadly.

First time I did it (a couple of months ago) I went with WSL because I'm so used to using *nix type tools, commands and shell. But sooner rather than later I started having problems working with files, searching them from the Windows side, it all seemed a bit too much. I went back to macOS. I have since then learned how to avoid these problems.

Nevertheless, I installed Windows again on my MacBook and this time I didn't go for WSL, I tried to get the native tools that I need on Windows itself and surprisingly, it's all there! For me, of course, this is a personal experience. Node is there along with NPM and nvm, MongoDB is there, Apache, Nginx, Ngrok, Git, python, VSCode, Sublime Text and a bunch more not worth for the discussion.

Everything is running smoothly and I'm actually liking it a lot! Some think I prefer over macOS, others I prefer macOS or I'm too used to it after years of using, learning, costumizing.

Sometimes it's a bit of a pain in the ass to discover the equivalent software to do some tasks, but that is not a shortcoming of the OS, only of me being used to it.

I have been using Windows exclusively for the past 3 or 4 weeks and if it goes smoothly as it has been until now, my next laptop won't be an over-priced but less-than-perfect machine. Seriously Apple, no one is happy with you anymore! And by "no one" I mean me and my opinions, I don't want to start this discussion on this thread :)

Collapse
 
shymi profile image
shymi • Edited

I use mostly Windows environments in my everyday work and use chocolatey for installing most of the dev related things. Chocolatey gives you the option in Windows, which nix users had for eternity - to easily update/install/remove programs from the command line. The apps are updated regularly in their repos so you have access to the latest version of most software and it helps a lot to set up new a environment/update an older one.

Collapse
 
gerbosan profile image
Carlos A.

Well, that's one of my fears too. Having to change my work environment and live with constant fear of instability. Windows Updates are kind of unpredictable so I read.

Still, having to gather all this info is amazing, thanks for the hard work. Good luck in this new job.

Collapse
 
bitdweller profile image
Pedro Pimenta

MacOS updates are also a gamble. You never know when it's gonna break whatever tools you use. But maybe these only happen on major updates and windows on smaller updates? I'm not sure. Either way, both OS updates can make your tools stop working.

Collapse
 
gerbosan profile image
Carlos A.

I remember reading a little about updating to Catalina and that I should wait. Same goes for Linux (though I wish apt could list the security updates like zypper). For what I read about Windows 10 updates, they are mandatory for the cheapest versions.

Collapse
 
louisefindlay23 profile image
Louise

WSL2 is great. I gave it a spin now you don't have to be on the Slow ring to get the Windows update needed, just the latest feature release.

I'll probably use it for docker containers since I use Git Bash and Windows tools (npm and MongoDB etc.) for web development.

Collapse
 
jonrandy profile image
Jon Randy 🎖️

What kind of backwards company forces its devs to use Windoze?

Some comments may only be visible to logged-in visitors. Sign in to view all comments.