Before we build anything bigger, we need a working Bun setup.
The goal of this chapter is simple:
- install Bun
- verify it works
By the end, your computer will be ready for the rest of the book.
The Command Line
The command line is where you type text commands to control your computer.
In this book, we will use the command line constantly. You will use it to install Bun, create projects, run code, and manage your application.
You may hear several related terms:
- terminal: the app window you open
- shell: the program that reads and runs commands
- prompt: the place where you type
People often use these terms loosely. For now, that is fine. What matters is simple: this is the place where we run commands.
Note: In this book, we will show shell commands with the standard
$prompt to keep examples consistent across platforms. Your prompt may look different, especially on Windows, and that is fine.
On Windows
We will use PowerShell.
Open the Start menu, search for PowerShell, and open it. You will see a window with a prompt where you can type commands.
On macOS
We will use the built-in Terminal app.
Open Spotlight with Command + Space, type Terminal, and open it. You will see a prompt where you can type commands.
On Linux
Open your system’s terminal application. The name varies by desktop environment, but it is usually easy to find by searching for Terminal in your applications menu.
Do not worry about the text shown before the cursor. It is different on every computer. In this book, we will focus on the commands themselves.
Shell Commands
We only need a small set of shell commands to get started.
You do not need to memorize dozens of commands. Most day-to-day work at this stage comes down to a few basics: finding where you are, moving to a folder, creating a folder, and stopping a running command.
Type each command and then press Enter or Return to run it.
Find where you are
Use pwd to show your current location.
Same command on macOS, Linux, and Windows:
$ pwd
You should see the folder you are currently in like this:
/Users/brian
List files and folders
Use ls (or dir on Windows) to see what is in the current folder.
Create and move into a new folder
Use mkdir, which means make directory.
$ mkdir learn-bun
Then move into it:
$ cd learn-bun
This is the basic pattern we will use throughout the book: create a folder, move into it, then start a project. At this point, you should be inside a new learn-bun folder and ready to install Bun or create your first project.
Clear the screen
Use clear (or cls on Windows) to tidy up when the terminal gets cluttered.
Stop a running command
When a server or script is running, press:
Ctrl + C
You will use this constantly while developing.
Open the current folder in VS Code
If you are using VS Code and the command is available:
$ code .
The dot means “open the current folder.”
If it does not work, open VS Code manually and choose File → Open Folder.
You can also check the official VS Code documentation for how to enable the code command in your terminal.
You do not need to become a command-line expert in this chapter. You only need to be comfortable enough to move around, create folders, and run the commands we use in the book.
Install Git
Git is a source control system. It keeps a history of your code so you can track changes, recover from mistakes, and work in a more professional way. We use it here so you build the habit of saving progress as you go, just like you would on a real project.
Git may already be installed. Check with:
$ git --version
If you see a version number, Git is installed. Skip ahead to Configure Git. If you see "command not found" or similar, install it below.
macOS
The easiest options are:
Install Xcode Command Line Tools:
$ xcode-select --install
or, if you use Homebrew:
$ brew install git
Git’s official macOS install page lists both options.
Linux
Install Git with your distribution’s package manager.
Debian / Ubuntu
$ sudo apt install git-all
Fedora
$ sudo dnf install git-all
Windows
The easiest option is to download and run the official Git for Windows installer from the Git website.
Check that it worked
After installing, run:
$ git --version
You should see a version number, confirming Git is installed.
Configure Git
$ git config --global user.name "Your Name"
$ git config --global user.email "yourname@email.com"
$ git config --global init.defaultBranch main
You can update these later by running the same commands again with your current name or email.
Install Bun
Now we install Bun. We will use one method per platform:
- macOS — Homebrew
- Linux — the official install script
- Windows — PowerShell
macOS
$ brew install bun
Later, upgrade with brew upgrade bun
Linux
$ curl -fsSL https://bun.com/install | bash
Windows
$ powershell -c "irm bun.sh/install.ps1|iex"
Bun requires Windows 10 version 1809 or later. After installation, close PowerShell and open it again.
After installing, verify Bun with:
$ bun --version
You should see a version number.
Then:
$ bun --revision
You should see the Bun version plus a commit identifier.
If bun --version does not work, Bun may not be in your system PATH. Check the Bun installation docs for the platform-specific fix.
Confirm Bun can run code
Create a file called hello.ts:
$ echo "console.log('Bun is running!');" > hello.ts
Run it with Bun:
$ bun run hello.ts
You should see:
Bun is running!
Conclusion
Your development environment is ready. You installed Bun, confirmed that it works, and learned the command-line basics we will use throughout the book. You also installed Git so you can start building with version control from the beginning.
That is enough for now. In the next chapter, we will create our first Bun project and start writing code.
Get notified when Part II ships.
One email per release. No spam, no upsells. Just the next set of chapters when they're ready.