Get up and Running with Meteor in WSL2
Tags: meteor, wsl2, node, mongodb
Published: 2020-08-08 17:56:18

Getting started with Meteor on Windows Subsystem Linux 2 (WSL2) is easy, but it requires a few departures from the Meteor Developers documentation.

### Step 1:

On WSL2? Install the latest official Meteor release from your terminal:

```
curl https://install.meteor.com/ | sh
```

Note: You may need to use the sudo command to install Meteor. If you do a prompt will pop up for you to enter your WSL2 root password.

If installed correctly you should see:
```
ricky@DESKTOP-ULOB7UG:~$ curl https://install.meteor.com/ | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7915    0  7915    0     0  40589      0 --:--:-- --:--:-- --:--:-- 40589
Removing your existing Meteor installation.
Downloading Meteor distribution
######################################################################## 100.0%

Meteor 1.10.2 has been installed in your home directory (~/.meteor).
Writing a launcher script to /usr/local/bin/meteor for your convenience.
This may prompt for your password.
[sudo] password for ricky: 

To get started fast:

  $ meteor create ~/my_cool_app
  $ cd ~/my_cool_app
  $ meteor

Or see the docs at:

  docs.meteor.com

Deploy and host your app with Galaxy:

  www.meteor.com/hosting
```

### Step 2:

Now that the installation is complete we need to change an environment variable to prevent issues when running MondoDB. 

To continue we need to vi and edit a file at:
```
.meteor/packages/meteor-tool/.1.10.2.121ry7f.gueme++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/tools/packaging/catalog/catalog-remote.js
```
Note: This file path will change depending on the version installed.

To do this run the following command after changing the path to match your home directory: 

```
vi /home/ricky/.meteor/packages/meteor-tool/.1.10.2.121ry7f.gueme++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/tools/packaging/catalog/catalog-remote.js
```

If vi tells you [Permission Denied] simply back out of vi using :q and run the following command after changing it to match your home directory:

```
sudo vi /home/ricky/.meteor/packages/meteor-tool/.1.10.2.121ry7f.gueme++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/tools/packaging/catalog/catalog-remote.js
```

Once you have the file open we need to change the following code around line 31: 

```
const JOURNAL_MODE = process.env.METEOR_SQLITE_JOURNAL_MODE || "WAL";
```

To read:

```
const JOURNAL_MODE =
  process.env.METEOR_SQLITE_JOURNAL_MODE || "TRUNCATE";
```

To do this using vi simply arrow up or down to the line and type :R to edit the line, once finished, hit ESC. Now exit vi using :wq to save and exit.

If you had to run sudo to edit the file you need to modify it's permissions. 

To do this run the following command changing it's home directory to match yours:

```
chmod +rw  /home/ricky/.meteor/packages/meteor-tool/.1.10.2.121ry7f.gueme++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/tools/packaging/catalog/catalog-remote.js
```

### Step 3: 

You are ready to create your Meteor app! 

To create a Meteor app run the following command:

```
meteor create ~/myapp
```

This command creates a meteor app in the home directory of WSL2. Creating the application in the home directory avoids errors listed in the error section of this guide. 

If your app was created successfully you should see:

```
ricky@DESKTOP-ULOB7UG:~$ meteor create ~/myapp
Created a new Meteor app in '/home/ricky/myapp'.

To run your new app:                          
  cd /home/ricky/myapp                        
  meteor                                      
                                              
If you are new to Meteor, try some of the learning resources here:
  https://www.meteor.com/tutorials            
                                              
When you’re ready to deploy and host your new Meteor application, check out Galaxy:
  https://www.meteor.com/hosting              
                                              
To start with a different app template, try one of the following:

  meteor create --bare       # to create an empty app
  meteor create --minimal    # to create an app with as few Meteor packages as possible
  meteor create --full       # to create a more complete scaffolded app
  meteor create --react      # to create a basic React-based app
  meteor create --typescript # to create an app using TypeScript and React
```

Now you are ready to go with Meteor!

### Step 4:

Let's finish up by ensuring everything is running correctly!

First let's start the Meteor server.

To start the server simply type the following:

```
cd myapp
meteor
```

If started correctly you should see:

```
[[[[[ ~/myapp ]]]]]                           

=> Started proxy.                             
=> Started MongoDB.                           
=> Started your app.                          

=> App running at: http://localhost:3000/
```

Alright, there is one more thing to check. We need to ensure that Meteor Mongo will start. 

To do this open a second WSL2 window and run the following command in the directory you just created your app in.

```
meteor mongo
```

If everything worked above you should see:

```
MongoDB shell version v4.2.5
connecting to: mongodb://127.0.0.1:3001/meteor?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0a0211ad-c3d5-478f-8427-7f90d2f54cd4") }
MongoDB server version: 4.2.5
meteor:PRIMARY> 
```

Congratulations you are up and running with Meteor in WSL2! If you've run into an error check below to see the cause. 


##Errors you may run into using WSL2:


### Error From Creating an App in a Windows Directory

#### Error

User gets the following message after creating a Meteor project on a mounted Windows drive.

```
ricky@DESKTOP-ULOB7UG:/mnt/c/Meteor/todo$ meteor
[[[[[ /mnt/c/code/Meteor/todo ]]]]]           

=> Started proxy.                             
Unexpected mongo exit code null. Restarting.  
Unexpected mongo exit code null. Restarting.  
Unexpected mongo exit code null. Restarting.  
Can't start Mongo server.                     
ricky@DESKTOP-ULOB7UG:/mnt/c/Meteor/todo$
```

#### Fix

A quick fix to this is to create your project within your home directory in WSL2. 

In WSL2 run the following command to create a project in your home directory:

```
meteor create ~/todo 
```

### Error from not changing from WAL to Truncate

#### Error 
Running the following command:

```
meteor mongo
```

The user gets:

```
Error: SQLITE_PROTOCOL: locking protocol
Retrying after error Error: SQLITE_PROTOCOL: locking protocol
=> awaited here:
at Promise.await
(/home/ricky/.meteor/packages/meteor-tool/.1.10.2.121ry7f.gueme++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/meteor-promise/promise_server.js:60:12)
at Db._execute (/tools/packaging/catalog/catalog-remote.js:361:8)
at /tools/packaging/catalog/catalog-remote.js:150:10
at Db._retry (/tools/packaging/catalog/catalog-remote.js:162:16)
at new Db (/tools/packaging/catalog/catalog-remote.js:149:8)
at RemoteCatalog.initialize (/tools/packaging/catalog/catalog-remote.js:699:15)
at /tools/cli/main.js:875:20 {
errno: 15,
code: 'SQLITE_PROTOCOL'
```
#### Fix
To correct this error edit the [meteor/tools/packaging/catalog/catalog-remote.js](https://github.com/meteor/meteor/blob/master/tools/packaging/catalog/catalog-remote.js) using the steps above. 

### Notes:

[Meteor Documentation](https://guide.meteor.com/#quickstart) 
[Notes on Moving Meteor Development to WSL Debian](https://chrisfleischhacker.wordpress.com/2019/10/17/notes-on-moving-meteor-development-to-wsl-debian/)
[Support "Bash on Windows" #154](https://github.com/meteor/meteor-feature-requests/issues/154)
[TRUNCATE journal mode for packaging DB on Windows like file systems #9644](https://github.com/meteor/meteor/pull/9644)