Windows Dev and setup for RedwoodJS is more challenging than macOS or Linux because is don’t work out of the box. You need a shell to run Node.JS and you got a tone of it, like git-bash or PowerShell.
However, I really believe that Windows Subsystem for Linux is the TheBest™ Windows setup.
If you don’t believe me, here citation from Microsoft itself :
I’m totally open to conversations, and it’s also okay to have personal preference.
The goal here is to have something that works for everyone, easily, without Windows specific bugs.
Before we start I want to answer to these concerns of using WSL2 from the last topic
The 2 first points is caused by the dynamic memory allocation of WSL, in the last beta update of Windows, the memory allocation should be better, but it will always be more demanding when you run 2 system at the same time. My recommendation is to have at least 16Gb of memory to work on a Redwood project and 32Gb when you work on the framework. I know is a lot, but it’s the only way to have a smooth experience on WSL because at the end is virtualisation. Tip : if you want to work a something more lite, I suggest making a dual boot with Ubuntu to have a lean system, you can follow every of this doc except installing WSL.
The last point is solved since the new Redwood extension (redwood-kaimana) is now working with WSL2.
So now let’s start this setup process!
You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.
In some cases, you need to enable virtualisation on your BIOS.
You can install everything you need to run Windows Subsystem for Linux (WSL) by entering this command in PowerShell or Windows Command Prompt and then restarting your machine.
This command will enable the required optional components, download the latest Linux kernel, set WSL 2 as your default, and install a Linux distribution for you (Ubuntu by default).
The first time you launch a newly installed Linux distribution, a console window will open, and you’ll be asked to wait for files to decompress and be stored on your machine. All future launches should take less than a second.
Once you have installed WSL, you will need to create a user account and password for your newly installed Linux distribution
You can Install Windows Terminal, is really nice open-source app to manage all of your shells. But most of the time, the VSCode Terminal is the way to go.
Open your Ubuntu command line.
Update your packages:
sudo apt update
Install cURL with:
sudo apt-get install curl
Install nvm, with:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
To verify installation, enter:
command -v nvm…this should return ‘nvm’, if you receive ‘command not found’ or no response at all, close your current terminal, reopen it, and try again. Learn more in the nvm GitHub repo.
List which versions of Node are currently installed (should be none at this point): nvm ls
Install the latest stable LTS release of Node.js :
nvm install --lts
List what versions of Node are installed:
nvm ls…now you should see the two versions that you just installed listed.
Verify that Node.js is installed and the current default version with: node --version. Then verify that you have npm as well, with: npm --version (You can also use which node or which npm to see the path used for the default versions).
Install Yarn with:
sudo apt install yarn
Install PostgreSQL with:
sudo apt install postgresql
If you have problems with yarn you should probably remove cmdtest and install Yarn again :
sudo apt remove cmdtest
To install VS Code and the Remote-WSL Extension:
Download and install VS Code for Windows. VS Code is also available for Linux, but Windows Subsystem for Linux does not support GUI apps, so we need to install it on Windows. Not to worry, you’ll still be able to integrate with your Linux command line and tools using the Remote - WSL Extension.
Other code editors, like IntelliJ, Sublime Text, Brackets, etc. will also work with a WSL 2 Node.js development environment, but may not have the same sort of remote features that VS Code offers.
At this point we should be able to run this command on your favourite terminal who run bash on Ubuntu:
yarn create redwood-app my-redwood-app
When they wrote this could take a while, this really take a while the first time, don’t worry.
After you see : Fire it up! , it’s time to have fun!
So go to your new project with :
And if you are not already on VScode, here’s a trick :
That will open VScode with your project on WSL automatically.
You can now start your dev server with :
yarn rw dev
Another WSL magic trick, your project will open on your favourite Windows browser (Microsoft Edge, right?).
Database is always to most tricky part and is not easier on Linux, so I made a quick setup for PostgreSQL.
Enter inside Postgres user as admin with :
su - postgres
and create databases for your project :
You also need to create a password for the database user
psql to enter inside the database and write this query
ALTER USER postgres PASSWORD 'mypassword';
Inside your project edit the
.env file with these 2 new lines
Use this command to start the DB server
sudo service postgresql start
and restart your dev server
That’s it !
Q : Why I see an error like
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/swapfile.sys'
A : You can use Ubuntu inside a Windows folder, but that will always cause permissions error. Before you use CRWA or git clone, check if your folder path start with a “~” or go to it with
Q : Can I use WSL for RedwoodJS framework contribution ?
A : Yes, every script should work on WSL and rwfw also work well
I wish this doc can help people to get start with RedwoodJS on WSL. If you have questions or see mistakes, I will be happy to answer !