Whether you want to create a web app, a command-line tool, a desktop app, or a browser extension, Bun Js can help you do it with ease and efficiency.
In this article, you will learn how to install and run Bun Js on Ubuntu, one of the most popular and user-friendly Linux distributions. You will also learn how to create a simple Hello World program, bundle it, test it, install packages, use Web-standard APIs, use TypeScript, and use JSX with Bun Js.
Before you begin, make sure you have the following requirements:
- A computer with Ubuntu 20.04 or later installed. You can download Ubuntu from its official website or update your existing Ubuntu system using the Software Updater app.
- An internet connection to download Bun Js and other packages.
- A terminal emulator to run commands. You can use the default Terminal app or any other terminal emulator of your choice.
Install Bun Js
Start by updating and upgrading the server packages to the latest version available.
sudo apt update sudo apt upgrade -y
Install Unzip if you don’t have unzip installed, it is required to extract the Bun package. Execute the below command to install Unzip.
sudo apt install unzip
The next step is to install Bun Js on your system. You can do this by running bash or zsh commands in your terminal. For example, you can run the following command to install Bun Js
curl -fsSL https://bun.sh/install | bash
Restart your terminal or run the below command to use the bun command.
username with the username you have logged in.
To check if Bun Js is installed correctly, you can run the following commands in your terminal:
These commands will output the version and help information of Bun Js respectively. You should see something like this:
Create a Hello World Program
hello.js in your current directory and write the following code in it:
This code uses the
console.log function to print a message to the standard output stream. This function is part of the Web-standard Console API that Bun Js provides.
You can also use other Web-standard APIs with Bun Js, such as fetch, WebSocket, FormData, etc. These APIs are based on the specifications defined by the World Wide Web Consortium (W3C) and are widely used by web developers. Bun Js implements these APIs using native libraries and modules, so you don’t need to install any external dependencies or polyfills.
Run the Program
To run the program, you can use the bun run command in your terminal. For example, you can run the following command to run the hello.js file:
bun run hello.js
The bun run command has some options and flags that you can use to customize its behavior. For example,
--watch flag: Watch for changes in the file and rerun it automatically
--debug flag: Enable debugging mode and attach a debugger to the process
--inspect flag: Enable inspection mode and connect a browser or an IDE to inspect the code
--help flag: See all the available options and flags
Upgrade Bun Js
You can upgrade Bun Js easily using the below command.
This command will upgrade Bun Js to latest version available.
How can I upgrade Bun Js to the latest version?
You can upgrade Bun Js to the latest version by running bun upgrade command in your terminal. This will download and install the latest release of Bun Js from its official website.
How can I uninstall Bun Js from Ubuntu?
You can uninstall Bun Js from Ubuntu by running bun uninstall command in your terminal. This will remove all files and directories related to Bun Js from your system.
How can I contribute to Bun Js development or community?
You can contribute to Bun Js development or community by following its code of conduct, contributing guidelines, and roadmap.