GO_LATEST_VERSION= # Add the latest Go version here
cd ~/
wget https://go.dev/dl/go${GO_LATEST_VERSION}.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go${GO_LATEST_VERSION}.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
echo 'PATH="$PATH:/usr/local/go/bin"' >> ~/.profile
Geth - Install
Build the latest version of Geth.
GETH_VERSION_COMMIT_HASH= # e.g.3f907d6
cd ~
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum
git checkout ${GETH_VERSION_COMMIT_HASH}
make geth
Start the service and check it's working as expected.
Geth - Command Aliases
daemon-reload # Reload any changes made to the geth.service
geth-enable # Enable the geth.service
geth-start # Start the geth.service
geth-status # View the status of the geth.service
geth-log # View the geth.service logs
Geth - Update Scripts
Create Geth update script.
vim ~/geth-update.sh
~/geth-update.sh
#!/bin/bash
set -e
while true; do
read -p "Are you sure you want to update Geth? (Y/N) " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer Y or N.";;
esac
done
cd ~/go-ethereum
read -p "Enter the commit hash you want to checkout: " commit_hash
git fetch
git checkout $commit_hash
echo
echo "**************"
echo "Making Geth..."
echo "**************"
make geth
# Check if geth.service is running
service_was_running=0
if sudo systemctl is-active --quiet geth.service; then
service_was_running=1
echo "****************"
echo "Stopping Geth..."
sudo systemctl stop geth.service
fi
echo "Replacing previous version..."
sudo rm -rf /usr/local/bin/geth
sudo cp ~/go-ethereum/build/bin/geth /usr/local/bin
# Only start geth.service if it was running originally
if [ $service_was_running -eq 1 ]; then
echo "Restarting Geth..."
echo "******************"
sudo systemctl start geth.service
fi
Make the script executable.
chmod u+x ~/geth-update.sh
Geth - Configure JavaScript Console
Use --preload to load pre-written commands and functions stored in a script file.
vim ~/geth-console-script.js
~/geth-console-script.js
function blockInfo() {
var blockInfo;
web3.eth.getBlock(eth.blockNumber, function(e, r) { blockInfo = r; });
return blockInfo;
}
Check Geth details by attaching to the JavaScript console