DEV Community

Cover image for Install Bun on WSL
Ben Subendran
Ben Subendran

Posted on

Install Bun on WSL

Bun(https://bun.sh) is a new JavaScript runtime with a native bundler, transpiler, task runner and NPM client built-in. Bun is superfast compared to NodeJS.

Enable WSL from Windows Features

To turn on the Windows Subsystem for Linux feature, click the checkbox like this:

Image description

Install Linux Distro

  • To work with WSL, you should have installed at least one distro on your computer.

To install Ubuntu, Run this:

winget install -e --id Canonical.Ubuntu
Enter fullscreen mode Exit fullscreen mode

If you want to install any other distro, you can get it here by searching; https://winget.run/

After installed, To check all the available distros, run this:

wsl --list
Enter fullscreen mode Exit fullscreen mode
  • If you get any error, just update the wsl by running wsl --update. And install the distro again.

Install Bun

After setting up the Unix admin for the respective distro, run this(in your WSL terminal, not in CMD):

curl https://bun.sh/install | bash
Enter fullscreen mode Exit fullscreen mode

If there's any error occurs while unzipping, install the unzip package like this:

sudo apt install unzip
Enter fullscreen mode Exit fullscreen mode

Now you can unzip it, and the installation will be done in seconds.

To check the installed Bun version, run this:

bun -version
Enter fullscreen mode Exit fullscreen mode

Try React on Bun

To scrutinize the specialty of Bun, we'll try installing React via Bun.

The following command will create a React project inside the myapp folder.

bun create react ./myapp
Enter fullscreen mode Exit fullscreen mode

Installed path will be like this: wsl.localhost\Ubuntu\home\USER\myapp

Image description

To start the React app, run these commands:

cd myapp
bun dev
Enter fullscreen mode Exit fullscreen mode

Now you can see your React app by navigating to http://localhost:3000.

All this can take significantly less time than NodeJS. That's the magic what Bun can do.

Top comments (1)

Collapse
 
leonardozivieri profile image
Leonardo Zivieri

Some other thing that you can do is create a bun.bat in some folder, add this folder in PATH environment variable and add this script

@ECHO OFF
wsl bash -ic "bun %*"
Enter fullscreen mode Exit fullscreen mode

And voila! The bun is working on windows powershell and cmd to!