Skip to content

WISE Local Development using Windows Subsystem for Linux (WSL)

Jonathan Lim-Breitbart edited this page Feb 6, 2020 · 26 revisions

Enable Windows Subsystem for Linux and install a Linux distribution

Follow the instructions here: https://docs.microsoft.com/en-us/windows/wsl/install-win10. (I'm using Ubuntu from the Windows Store for my Linux distro.)

Set your Linux distribution to use WSL 2 (if supported)

Depending on your version of Windows, your system may support WSL 2, which includes a native Linux kernel and significant performance improvements.

Ensure that you are using WSL 2 on supported systems by following these instructions: https://docs.microsoft.com/en-us/windows/wsl/wsl2-install.

Install WISE

Start the Linux distro and complete initialization (if you haven't already done so): https://docs.microsoft.com/en-us/windows/wsl/initialize-distro.

1. Install Maven

$ sudo apt install maven
$ mvn -v

You should see output similar to:

Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.4, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.19.79-microsoft-standard", arch: "amd64", family: "unix"

2. Install Node & NPM

The following steps follow these instructions for install Node using nvm: https://gist.github.com/noygal/6b7b1796a92d70e24e35f94b53722219.

$ sudo apt-get install build-essential
# Check nvm for lastest version (using 0.35.1 in this example)
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
$ nvm install --lts
$ nvm use --lts
$ echo "nvm use --lts" >> .bash_profile

Run node -v and npm -v to verify installation.

3. Install Redis

Instructions for Ubuntu: https://anggo.ro/note/installing-redis-in-ubuntu-wsl/. (May vary slightly depending on your Linux distro).

Once Redis is installed, run redis-cli config set notify-keyspace-events Egx

4. Install Git, clone WISE project, install dependencies

$ sudo apt install git
$ git clone https://github.com/WISE-Community/WISE.git
$ cd WISE
# install node dependencies
WISE $ npm install
WISE $ chmod u+x wise.sh

5. Install MySQL and create WISE database

Install MySQL and start service

WISE $ sudo apt install mysql-server
WISE $ sudo service mysql start

Create WISE database and user:

# login as root (or set a password for root user and run `mysql -u root -p`)
WISE $ sudo mysql
# create new user wiseuser, password wisepass
mysql> create user 'wiseuser'@'localhost' identified by 'wisepass';
# create wise_database
mysql> create database wise_database default character set=utf8;
# give wiseuser access to the new database
mysql> grant all privileges on wise_database.* to 'wiseuser'@'localhost';
mysql> flush privileges;  
mysql> exit;

Create tables for wise_database by reading in the src/main/resources/wise_db_init.sql file:

# create tables for wise_database and load it with initial values
WISE $ mysql wise_database -u wiseuser -p < src/main/resources/wise_db_init.sql

6. Update .bash_profile and environment variables

I had to update my bash profile to get nvm to load correctly each time bash is started and to get ChromeHeadless (which is used for WISE unit tests) to run on WSL (more info).

Run sudo vim ~/.bash_profile (or swap vim for your favorite text editor), add the following to the file, and save and quit:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
nvm use --lts
# set CHROME_BIN env variable to point to the pre-installed Chrome binary on Windows
export CHROME_BIN=/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe

Add JAVA_HOME to /etc/environment. First, identify the path to your Java install:

WISE $ update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Nothing to configure.

Your output will vary, depending on your Java installation. Run sudo vim /etc/environment (or swap vim for your favorite text editor), add the path to the bin folder to the file (replacing with the path to your Java installation), and save and quit:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/bin/"

7. Set MySQL and Redis to start on Windows boot

Create a Windows startup script:

  • Press 'Windows+R' on the keyboard, then type shell:startup. This will open the startup folder (C:\Users\[username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup).
  • Create a new VB script file (called 'wsl-startup.vbs', for example) and open it for editing (right click -> Edit or just create a text file, paste in the contents and save as 'wsl-startup.vbs').
  • Paste the following and save:
Set oShell = CreateObject("WScript.Shell")
oShell.Run "wsl", 0
oShell.Run "bash -c ""sudo service redis-server start --daemonize yes; sudo service mysql restart;"""
  • This tells Windows to start WSL, then start redis and MySQL. The script will run whenever Windows starts up.

Invoking sudo commands from the Windows command line requires typing your Linux password. To avoid having to do this on startup, you can edit your sudoers file back in Linux.

  • Run sudo visudo.
  • Paste the following to the bottom of the file and save (replacing your username with your username):
username ALL=(ALL) NOPASSWD:ALL
  • This tells Linux to not require a password anytime your user runs a sudo command.

You can test the startup script by doing the following:

  • In Linux, stop MySQL and Redis:
WISE $ sudo service mysql stop
WISE $ sudo service redis-server stop
  • Run the Windows startup script (double click on the 'wsl-startup.vbs' file).
  • Go back to Linux and check to see that MySQL and Redis are running:
# Test that Redis is running.
WISE $ redis-cli
# You should see the Redis command line. Type 'ping' and press Enter.
127.0.0.1:6379> ping
# You should get this response:
PONG
# Exit the Redis cli.
127.0.0.1:6379> exit
WISE $

# test that MySQL is running
WISE $ sudo mysql
# You should see the following output:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.28-0ubuntu0.18.04.4 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# Exit MySQL.
mysql> exit;
WISE $

8. Run WISE

Build the applications: npm run build-dev-all (development mode) or npm run build-prod-all (production mode)

Start WISE: ./wise.sh run

Clone this wiki locally