This tutorial will guide you through the installation process for Singlenode Geth on Ubuntu Linux.
To update the repositories, run the following commands:
sudo apt update
sudo apt upgrade
This will update the repositories and upgrade any packages that need to be upgraded on your Linux machine.
Note: It is recommended to keep your system up-to-date to ensure the latest security patches are installed.
Download the Geth 1.11.6 stable file (.tar.gz) from the official website or GitHub repository.
You can download the latest stable version of Geth for Linux 64-bit directly from the official Geth website. Here's how:
- Go to the Geth website at https://geth.ethereum.org/downloads/
- Scroll down to the "Stable Releases" section.
- Find the "Geth & Tools {version number}" release and click on the "Linux (64-bit)" link next to it.
- The download will start automatically.
Extract the downloaded file using the following command:
sudo tar xvf geth-alltools-linux-amd64-{version number}.tar.gz
For Example :
sudo tar xvf geth-alltools-linux-amd64-1.11.6-ea9e62ca.tar.gz
This command will extract the Geth file that you downloaded earlier. You should replace {version number} with the actual version number of the file that you downloaded.
cd geth-alltools-llinux-amd64-1.11.6-ea9e62ca
This will change your current directory to the geth-alltools-llinux-amd64-1.11.6-ea9e62ca
directory.
Make the geth
file executable with the following command:
sudo chmod +x geth
This will give the geth
file executable permission.
sudo cp geth /usr/local/bin/
Verify that the Geth version is installed correctly by running the following command:
geth version
This will copy the geth
file to the /usr/local/bin/
directory, which is included in the PATH
variable, making it easier to run geth
from anywhere in the terminal.
Make a new directory for your single node setup with the following command:
mkdir singlenode
Navigate to the newly created directory with the following command:
cd singlenode
Create a new file named genesis.json in the singlenode directory using a text editor such as nano
or gedit
. For example, to create the file using gedit, run the following command:
gedit genesis.json
This will open a blank file in the terminal window. You can then add the necessary content to the file, which defines the initial configuration for the blockchain network.
Open the genesis.json
file with your preferred text editor and add the following content to the file:
{
"config": {
"chainId": 4321,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0
},
"alloc": {},
"difficulty" : "0x20000",
"gasLimit" : "0x8880000"
}
Save the file and close the text editor.
Create a new directory for your first node using the following command:
mkdir node1
Navigate back to the singlenode directory and Initialize Node 1 with the Genesis file using the following command:
cd ..
In your singlenode directory run the following command:
geth --datadir node1 init genesis.json
This will create the necessary files for the blockchain network in the node1
directory.
To start the node, enter the following command:
geth --http --http.corsdomain http://remix.ethereum.org --allow-insecure-unlock --http --http.port 8545 --http.addr 127.0.0.1 --http.corsdomain "*" --http.api "eth,net,web3,personal,miner" --datadir node1 --nodiscover --networkid 4321 --port 30303 console --rpc.enabledeprecatedpersonal
This command will start the node and provide access to the Geth console.
In order to start the Geth console, you first need to initialize the genesis block using the command in Step 12, and then start the node using the command in Step 13. You will need to repeat these steps every time you want to start the console.
You can simplify the process and avoid having to copy and paste the same commands every time by creating aliases for them. This will allow you to easily work with Geth without having to remember or type out the entire commands every time.
For aliasing follow the steps below:
- Open your
.bashrc
file with the following command:
gedit ~/.bashrc
- Scroll to the bottom of the file and add the following line:
alias mygeth='geth --http --http.corsdomain http://remix.ethereum.org --allow-insecure-unlock --http --http.port 8545 --http.addr 127.0.0.1 --http.corsdomain "*" --http.api "eth,net,web3,personal,miner" --datadir ~/singlenode/node1 --nodiscover --networkid 4321 --port 30303 console --rpc.enabledeprecatedpersonal'
-
Save the file and exit the editor.
-
Reload the
.bashrc
file with the following command:
source ~/.bashrc
- Now you can start the Geth console with the following command:
mygeth
With aliasing, you can easily start the Geth console by simply typing mygeth
in the terminal instead of running the lengthy command every time.