Skip to content
This section provides some common commands and examples to help you get started using the Anchor CLI.
1

Initialize the project

Create a new Anchor project by running the command shown below. It will create a new directory with the project name and use it to initialize a new Anchor project.
Terminal
For example, the command below will create a project called my-project. The my-project directory will contain a modular Rust program and a Rust test template that uses LiteSVM.
Terminal
To generate a TypeScript test template instead, choose one explicitly. For example, use the Mocha template:
Terminal
TypeScript test templates require Node.js and a JavaScript package manager.Then navigate to the project directory:
Terminal
See Anchor’s project file structure.
2

Build the program

To build your project, run the following command:
Terminal
You can find the compiled program in the /target/deploy directory.
Platform tools failed to installIf the build reports an invalid platform-tools directory, reinstall the SBF build tools, then retry the build:
Terminal
3

Deploy the program

To deploy your project, run the following command:
Terminal
This command deploys the program that anchor build wrote to target/deploy to the cluster specified in the Anchor.toml file. To target a different cluster, add --provider.cluster, for example anchor program deploy --provider.cluster devnet. If your workspace contains more than one program, select one with --program-name <name>.anchor program deploy replaces anchor deploy, which still works but prints a deprecation warning.
4

Test the program

To test your project, run the following command:
Terminal
This command builds your program and runs the test script defined in Anchor.toml.
For the default LiteSVM template, the test script is cargo test and no validator is started. For the Mocha or Jest templates on the localnet cluster, Anchor starts a local validator, deploys the program, runs the tests, then stops the validator.
Anchor CLI 1.2 builds SBPF v3 programs by default (it passes --arch v3 to cargo build-sbf), but the template that anchor init creates in Anchor 1.2.0 and 1.2.1 pins LiteSVM 0.10, which can’t load v3 programs. With those versions, anchor test on the default template fails with Err(Instruction(InvalidAccountData)) in tests/test_initialize.rs. Build for the v0 architecture, then test without rebuilding:
Terminal
Anchor 1.2.2 and later pin LiteSVM 0.15, which loads v3 programs, so anchor test works on the default template.Anchor 1.1.2 installed with AVM (as the installer does) runs with Solana CLI 3.1.10, which AVM installs and activates the first time anchor runs, so it builds v0 programs and isn’t affected. Without AVM, on Solana CLI 4.3 or later, anchor build fails with Platform tools v1.52 is incompatible with SBPFv3; see the workaround in Build your first program. The --arch flag of anchor build exists only in Anchor CLI 1.2 and later; with Anchor 1.1, pass it to cargo build-sbf after --.
JavaScript test runner errorsIf you selected a JavaScript or TypeScript test template, either of the following errors may indicate that Node.js or the configured package manager is not installed: