Run a Node on Linux and MacOS
If this is the first time for you to setup a validator node, head to our Validator Bootcamp 🚀. Please head to Run a node for instructions on how to setup a validator node with neard.
This doc is written for developers, sysadmins, DevOps, or curious people who want to know how to run a NEAR node on Linux and MacOS.
Running a Node using Docker​
For running a node using Docker, please refer to the Docker setup guide.
Compiling and Running a Node without Docker​
You can build and run a node without Docker by compiling neard locally. Steps in this section provide details of how to do this.
As a prerequisite, Rust needs to be installed on your machine.
For Mac OS, make sure you have developer tools installed and then use brew to install extra tools:
brew install cmake protobuf clang llvm jq
For Linux, install these dependencies:
sudo apt update
sudo apt install -y git binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev cmake gcc g++ python docker.io protobuf-compiler libssl-dev pkg-config clang llvm jq
Then clone the repo:
git clone https://github.com/near/nearcore.git
cd nearcore
Checkout the version you wish to build:
git checkout <version>
You can then run:
make neard
This will compile the neard binary for the version you have checked out, it will be available under target/release/neard.
Note that compilation will need over 1 GB of memory per virtual core
the machine has. If the build fails with processes being killed, you
might want to try reducing number of parallel jobs, for example:
CARGO_BUILD_JOBS=8 make neard.
NB. Please ensure you build releases through make rather than cargo
build --release. The latter skips some optimisations (most notably
link-time optimisation) and thus produces a less efficient executable.
If your machine is behind a firewall or NAT, make sure port 24567 is open and forwarded to the machine where the node is going to be running.
Finally, initialize the working directory and start the node. The
node needs boot nodes to find its first peers. The reference RPC
config.json has no boot nodes. Follow Fetch boot nodes with CHAIN_ID=testnet to set BOOT_NODES, then return here and continue in the same shell:
./target/release/neard --home ~/.near init --chain-id testnet --download-genesis --download-config rpc --boot-nodes "${BOOT_NODES:?}"
Check that network.boot_nodes in config.json is not empty:
jq -r '.network.boot_nodes' ~/.near/config.json
The command should print a comma-separated list of boot nodes. If it prints an empty line, the node has no peers to sync from. Add boot nodes as described in Update an existing configuration. Running neard init again does not add them, because it does not change an existing config.json.
Then start the node:
./target/release/neard --home ~/.near run
If you want to run localnet instead of testnet, you do not need
boot nodes. Run ./target/release/neard --home ~/.near init --chain-id localnet
instead, then start the node. (If you're running localnet you don't
need to open port 24567).
For validation, please follow the Validator Bootcamp.
Running a Node on the Cloud​
Create a new instance following the Hardware requirements.
Add firewall rules to allow traffic to port 24567 from all IPs (0.0.0.0/0).
SSH into the machine. Depending on your cloud provider this may
require different commands. Often simple ssh hosts-external-ip
should work. Cloud providers may offer custom command to help with
connecting to the instances: GCP offers gcloud compute
ssh, AWS
offers aws emr
ssh
and Azure offers az
ssh.
Once connected to the instance, follow the steps listed above.
Starting a node with epoch sync​
A new node syncs with Epoch Sync, so it does not need a data backup. Follow Fetch boot nodes with CHAIN_ID set to your network (mainnet or testnet). Return here and continue in the same shell, replacing <chain-id> with that network:
./neard init --chain-id <chain-id> --download-genesis --boot-nodes "${BOOT_NODES:?}"
Check that network.boot_nodes in config.json is not empty:
jq -r '.network.boot_nodes' ~/.near/config.json
The command should print a comma-separated list of boot nodes. If it prints an empty line, the node has no peers to sync from. Add boot nodes as described in Update an existing configuration. Running neard init again does not add them, because it does not change an existing config.json.
Then start the node with an empty data folder:
./neard run
Where <chain-id> corresponds to testnet or mainnet.