Setting up a new Ballerina Project

Setting up

Dakshitha Ratnayake
3 min readMay 5, 2022

If you’re following my Nobel prize laureates tutorial and/or completely new to Ballerina, I’ll walk you through how to install Ballerina, set up VS Code, and create a Ballerina project. If you’re already familiar with all of this, you can check out the post.

Steps:

  1. Follow instructions to download and install Ballerina here. We’ll be using Visual Studio Code(VS Code) to write Ballerina code. To install the Ballerina plugin for VS Code, follow the instructions here.
  2. Once the Ballerina installation is complete, verify if Ballerina is installed by typing bal in the command line. The output should be something like this:

3. The bal tool is the Ballerina build tool and package manager. We’ll be creating a package with the bal tool next. A package allows us to organise multiple Ballerina source files into a single working project. To create a new package called nobel_prizes, type the following:

bal new nobel_prizes

Output:

4. Let’s move to the created package directory and open VS Code. Type the commands given below. To open VSCode from your terminal with code ., follow the instructions here if you haven’t done so already.

cd nobel_prizescode .

5. When we open VS Code, we’ll see that the bal tool has also generated a set of files for us already. The Ballerina.toml file contains metadata that describes the project, and the bal tool uses the file to identify the root of a project. The main.bal file is a source file and it contains sample Ballerina code. Right now, it prints Hello, World! to the console. You can add any number of source files into a package, in this case it’s the nobel_prizes directory.

6. Because I’ve already installed and activated the Ballerina plugin for VSCode, you can see that the Ballerina syntax is highlighted.

7. Next, let’s run the main function to make sure that everything is running as expected. Select Terminal-> New Terminal from the menu bar as shown below:

8. In the Terminal pane, type the run command to run the main program:

bal run

The output “Hello, World!” will be displayed on the terminal as follows:

--

--