Anchor CLI Basics
This section walks through some common Anchor CLI commands to get you started. For more information on the Anchor CLI, see the Anchor documentation.
Initialize Project
To create a new Anchor project, run the following command:
$anchor init <project-name>
For example, to create a project called my-project
, run:
$anchor init my-project
This command creates a new directory with the project name and initializes a new Anchor project with a basic Rust program and TypeScript test template.
Navigate to the project directory:
$cd <project-name>
See the Anchor project's file structure.
Build Program
To build your project, run the following command:
$anchor build
You can find the compiled program in the /target/deploy
directory.
When running anchor build
, if you encounter the following errors:
After applying the preceding solution, attempt to run anchor build
again.
Deploy Program
To deploy your project, run the following command:
$anchor deploy
This command deploys your program to the cluster
specified in the
Anchor.toml
file.
Test Program
To test your project, run the following command:
$anchor test
This command builds, deploys, and runs the tests for your project.
When using localnet
as the cluster
in Anchor.toml
, Anchor automatically
starts a local validator, deploys your program, runs tests, and then stops the
validator.
When running anchor test
after creating a new Anchor project on Linux
or WSL, you may encounter the following errors if you don't have Node.js or Yarn
installed:
Permission denied (os error 13)
No such file or directory (os error 2)
Is this page helpful?