What is Bun ,Why you should care about it and How to install it in Windows

What is Bun ,Why you should care about it and How to install it in Windows

Welcome to my first blog and today's discussion is going to be around Bun.

What is Bun and why should we look into it?

Well on the official website https://bun.sh , its makers describe it as:

Bun is an all-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager.

Basically , you can consider it as something similar to NodeJS but its incredibly fast.

Its package manager is about 29 times faster than npm!

Bun is designed as a drop-in replacement for Node.js. It natively implements hundreds of Node.js and Web APIs, including fs, path, Buffer and more.

By the way its also a test runner which is again damn fast.
You can always check out the rest of the features and statistics on their official website.

Okay I get it that its worth looking into it , now tell me how to set it up in my local machine?

According to its makers, Bun is supported on macOS, Linux, and WSL.
For people with macOS and Linux , the setup is going to be really easy.But Windows users will have to do some extra steps to get it up and running.

Bun provides a limited, experimental native build for Windows. It is recommended to use Bun within Windows Subsystem for Linux.

Well you need to use WSL .Now lets follow these steps (I am assuming you have Windows 10 or higher):

  • Search for "Turn Windows features on or off" in your system , go into it and make sure "Windows Subsystem for Linux" box is checked.

  • Now search for Microsoft Store and install Ubuntu . Once its installed then on opening , an ubuntu terminal will open which will ask you to enter your username and password . After that , its setup is completed.

  • Now you can open Visual Studio Code , navigate to any folder you want and open the Ubuntu(WSL) terminal (now you would see that appearing with Powershell,cmd ...).

  • Now run this command first

       sudo apt install unzip
    

    This will install unzip which is a prerequisite for installing bun (it requires Kernel version to be minimum 5.1)

  • Now lets come to the command we all have been waiting for:

      curl -fsSL https://bun.sh/install | bash
    

    This will globally install bun irrespective of the folder you are in.

  • Now just as a verification whether we successfully installed bun or not ,run this command :

      bun --version
    

    It should return the current version.

So thats it ! You should have bun installed in your system and you can use it using Ubuntu(WSL).
Mac and Linux users can directly start from "unzip installation step" in their terminal.

I am facing some errors , what should I do?

  • The very first thing you should do is read the error , what it is stating and try to backtrack what step it could be referring to and think about what you could have gotten wrong. Or simply copy it and search it on stackoverflow or Bard or ChatGPT to get some further reference.

  • I am giving a youtube video link in case you want to understand it visually.

    https://youtu.be/uCMFaLyOk3U?si=uXvDfuEPOLN322qG

  • There could be some issues with WSL in your system that it might not be fully enabled . For that again , follow the error message, look into some yt videos and I am sure you will be able to solve it.

So whats next?

I am still learning about it and I am going to learn how to build RESTful API using Elysia . It is again built on top of Bun and again its super fast (about 21 times as that of express).
So stay safe and sound ! Thanks for reading !