Skip to content

WISE Local Development using Windows Subsystem for Linux (WSL)

Jonathan Lim-Breitbart edited this page Jun 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. Follow the instructions in the above link to use WSL 2.

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 Java Development Kit

$ sudo apt update && apt upgrade
$ sudo apt install default-jdk

2. Install Maven

$ sudo apt install maven
$ mvn -v

You should see output similar to:

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

3. 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.3/install.sh | bash
$ nvm install --lts
$ nvm use --lts
$ echo "nvm use --lts" >> .bash_profile

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

4. Install Redis

Instructions for Ubuntu: https://redislabs.com/blog/redis-on-windows-10/ (may vary slightly depending on your Linux distro).

Once Redis is installed and running (sudo service redis-server start), run redis-cli config set notify-keyspace-events Egx

5. 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

6. 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

7. 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"

8. Set MySQL and Redis to start on Windows boot

Create a startup script:

WISE $ cd ~
$ touch startup.sh
$ chmod u+x startup.sh
$ vim startup.sh # or use your favorite editor

Add the following to your startup.sh script and save the file:

sudo service redis-server start --daemonize yes; sudo service mysql restart;

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.

  • 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.

Create a Windows Task to run the startup script on boot:

  • Open the Windows Task Scheduler
  • Choose "Create Basic Task"
  • Give the task a name ("WSL startup", for example)
  • For Trigger, choose "At log on"
  • For Action, choose "Start a program"
  • For Program/script, input "C:\Windows\System32\bash.exe" or click "Browse" and find "bash" in your Windows\System32 folder
  • In the "Add arguments" field, enter -c "/home/{username}/startup.sh", replacing {username} with your WSL user
  • Save the task

You can test the startup script by doing the following:

  • In Linux, stop MySQL and Redis:
$ sudo service mysql stop
$ sudo service redis-server stop
  • Run the startup task in Task Scheduler by right clicking on the task and selecting "Run"
  • Go back to Linux and check to see that MySQL and Redis are running:
# Test that Redis is running.
$ 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
$

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

Copyright (c) 2000, 2020, 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;
$

9. Run WISE

Build the applications and start WISE:

$ cd WISE
# Build WISE. This builds a development environment. To build a production environment, use `npm run build-prod`.
$ WISE npm run build-dev
# Start WISE
$ WISE ./wise.sh run

10. Setup VS Code

[to be completed]

Clone this wiki locally