Table of Contents
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.
Prerequisites
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.
- A code editor to write and edit JavaScript code. You can use any code editor that supports JavaScript syntax highlighting, such as VS Code, Atom, Sublime Text, etc.
- A browser to view and test your web app. You can use any browser that supports modern JavaScript features, such as Chrome, Firefox, Edge, etc.
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.
source /home/username/.bashrc
Replace 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:
bun --version
These commands will output the version and help information of Bun Js respectively. You should see something like this:
1.0.1
Create a Hello World Program
Now that you have installed Bun Js on your system, you can start writing and running JavaScript code with it. To create a simple Hello World program, you can use your code editor to create a file named hello.js
in your current directory and write the following code in it:
console.log("Hello, world!");
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
This command will execute the JavaScript code in the file and output the result to the standard output stream. You should see something like this:
Hello, world!
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.
bun upgrade
This command will upgrade Bun Js to latest version available.
Conclusion
In this article, you have learned how to install and run Bun Js on Ubuntu, one of the most popular and user-friendly Linux distributions. You have also learned how to create a simple Hello World program and test it. By following these steps, you have been able to set up Bun Js on Ubuntu in 10 minutes or less and start writing awesome JavaScript code.
FAQs
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.