CLI commands

The Ballerina Tool is your one-stop-shop for all the things you do in Ballerina.

Use the Ballerina tool

The Ballerina Tool is a command-line tool for managing Ballerina source code. It helps you to manage Ballerina packages and modules, test, build, and run programs, etc.

It also enables you to easily install, update, and switch among Ballerina distributions.

In the CLI, execute the bal help command to view all the actions you can perform with the Ballerina Tool as shown below.

You can use it in the following format.

bal <COMMAND> <ARGUMENTS>

Tip: You can view details of the commands by executing the bal help <COMMAND>. For example, the following is the output of the bal help pull command.

Core commands

These everyday commands are your best friends! They address the very basics of programming in Ballerina such as compiling, running, testing programs, and generating their documentation.

buildCompile a standalone .bal file, or an entire package into an executable JAR file. For more information, see Getting started with Ballerina.
runBuild and run a standalone .bal file, an entire package, or a previously-built program. For more information, see Getting started with Ballerina.
testRun tests of a Ballerina package. For more information, see Testing a Simple Function.
docGenerate API documents for all public symbols of a Ballerina package. For more information, see Generating code documentation.
packCreate the distribution format (.bala) of the current package

Package commands

Ballerina packages are the way to organize real-world Ballerina development tasks. The last 3 commands given below allow you to work with the Ballerina Central and also to share Ballerina packages with others in a safe, secure, and dependable way.

newCreate a Ballerina package. For more information, see Create a new package.
initCreate a new Ballerina package in the current directory.
addAdd a new module to the current package.
pullPull a package from Ballerina Central.
pushPublish a package to Ballerina Central. For more information, see Publish packages to Ballerina Central.
searchSearch Ballerina Central for packages.
semverValidate SemVer compatibility of the local package changes against any previously published version(s) in Ballerina Central.
graphPrint the dependency graph in the console.

Other commands

These powerful supporting tools extend Ballerina to various ecosystem technologies that are inherently cloud-native. This functionality will grow over time and will even be developer extensible in the future.

cleanClean all artifacts generated by the build command for a package.
formatFormat Ballerina source files as per the Coding Conventions.
grpcThis is the gRPC stub/skeleton generation tool. For more information, see gRPC/Protocol Buffers.
graphqlThis is the GraphQL client generation tool. For more information, see Ballerina GraphQL client tool support.
openapiThis is the OpenAPI (Swagger) stub/skeleton generation tool. For more information, see Ballerina OpenAPI support.
asyncapiTool to generate Ballerina sources for a given AsyncAPI definition. For more information, see Ballerina AsyncAPI support.
bindgenUse this tool for auto-generating Ballerina bridge code for Java APIs. For more information, see Call Java code from Ballerina.
shell Use this to run a REPL instance of Ballerina and execute small snippets of code.
versionTells you the version of the distribution you are currently using, the language specification version on which it is based, and the update tool version, which is currently in use.
helpPrints the usage details of any Ballerina command (e.g., bal help pull).

Update commands

distManage Ballerina distributions. For more information, see Update Tool.
updateUpdate the Ballerina Tool. For more information, see Update Tool.