## Introduction
**Geth**, which is the short form for Go Ethereum, is a **Go** implementation of the **Ethereum protocol** designed to allow developers run **nodes** on the Ethereum network, interact with the Ethereum Blockchain, validate transactions, and also execute smart contracts.
Key features of Geth include:
* Ethereum Node Implementation.
* JSON-RPC API methods.
* Smart Contract Execution (EVM Support).
* Sync Modes.
## Core Functionality
### Ethereum Node Implementation.
An Ethereum node is made up of two parts:
* The **execution client** that handles transactions and smart contracts,
* The **consensus client** that ensures the blockchain stays in agreement (consensus).
Geth is an **execution client** that is coupled to a consensus client to keep track of the Ethereum blockchain. It is responsible for handling transactions, managing states and supporting the Ethereum Virtual Machine EVM.
| Component | Role |
|--------------------|----------------------------------------------------------------------------------------------|
|**Geth (Execution Client)** | Executes Ethereum transactions, manages state, and provides RPC APIs for developers|
|**Consensus Client** | Ensures the node follows the correct chain by handling consensus and syncing blocks |
#### Sync Modes
Syncing is the process that updates Geth to the latest Ethereum block and current global state. A Geth node is synced by various means depending on the **speed, storage requirements** and **trust assumptions**. To properly sync, Geth connects to a consensus client, especially now that Ethereum uses **proof-of-stake**.
| Sync Mode | Description | Use Case | Pass Command |
|------------------|-------------------------------------------------------------------------------------------------|----------------------------------------------|--------------------------------------------------------|
| **Snap (Default)** |starts from recent block and syncs from there to the head of the chain,it keeps only the most recent 128 block states in memory. | Default mode, suitable for most users. | `--syncmode snap` |
| **Full** |A full block-by-block sync generates the current state by executing every block starting from the **genesis** block. | High trust, validation-focused nodes. | `--syncmode full` |
| **Archive** | Retains all historical data right back to **genesis**. | Querying **historical state data** instantly.| `--syncmode full --gcmode archive` |
### JSON-RPC API
Developers interact with Geth by sending requests to specific **JSON-RPC API** methods. The RPC requests are sent to the node and the response is sent to the client using **transport protocols**. These RPC methods are grouped into various categories, depending on their functions. Meanwhile, all method names are made up of the **namespace**, an **underscore**, and the actual **method name** within the namespace.
The `eth_call` method for example resides in the `eth` namespace.
**Transport Protocols**
Geth allows developers interact with the blockchain using three types of communication methods, called transport protocols. They are:
**IPC**, **HTTP** and **Websockets**.
| Transport | Direction | Good For | Default Port | Enable With |
| ------------- | ---------- | ------------------------------ | ------------ | ------------ |
| **IPC** | Local environment | Fast, secure (Unix systems) | N/A | Auto-enabled |
| **HTTP** | One-way | Most common, tools & browsers | `8545` | `geth --http` |
| **WebSocket** | Two-way | Event subscriptions, real-time | `8546` | `--ws` |
## Running & Configuring Geth
### Installation
Geth can be installed via the following methods:
* Package managers
* Downloading a pre-built bundle.
* Docker container.
* Build from source code.
#### Package managers
**macOS (via Homebrew)**
The easiest way for developers to install Geth is to use the **Geth Homebrew tap**. To check if Homebrew is already installed, run the command:
```
brew -v
```
If it returns a version, Homebrew is already installed. If it doesn't, [install Homebrew](https://brew.sh/).
After installing Homebrew, run the following command to install Geth:
```
brew tap ethereum/ethereum
brew install ethereum # Stable version
brew install ethereum --devel # Latest dev version
```
To update Geth, run the following command:
```
brew update
brew upgrade
brew reinstall ethereum
```
**Ubuntu (via PPA)**
Install Geth on Ubuntu-based distributions using built-in launchpad **PPAs** (Personal Package Archives).
To add Ethereum PPA, run the following command:
```
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
```
To install Geth, run the following command:
**For stable version**
```
sudo apt-get update
sudo apt-get install ethereum
```
**For dev version**
```
sudo apt-get update
sudo apt-get install ethereum-unstable
```
**Windows**
The easiest way to install Geth on windows, is to visit the Geth [Downloads](https://geth.ethereum.org/downloads) page and download the Windows installer or ZIP file
**Install Geth**:
* The **install wizard** offers the user the option to install Geth, or Geth and the developer tools
* Run the **installer** and follow the **prompts**.
* The installer adds `geth` to your system's `PATH` automatically.
* Alternatively, you can extract the ZIP file and run `geth.exe` from the command prompt.
To update Geth, download and install the latest version using the steps above.
Note: Use `geth --help` in the command prompt to view available commands.
**FreeBSD via pkg**
Geth can also be installed on FreeBSD via the package manager `pkg`. To download and install Geth, enter the command:
```
pkg install go-ethereum
```
This installs Geth software and the following developer tools: `clef`, `devp2p`, `abigen`, `bootnode`, `evm`, `rlpdump` and `puppeth`.
To update an existing Geth installation to the latest version, enter the following command:
```
pkg upgrade
```
**FreeBSD via ports**
Geth can also be installed using ports, by navigating to the `net-p2p/go-ethereum` ports directory and running `make install` as root:
```
cd /usr/ports/net-p2p/go-ethereum
make install
```
This installs the Geth software and the following developer tools: `clef`, `devp2p`, `abigen`, `bootnode`, `evm`, `rlpdump` and `puppeth`. The binaries for these tools are saved in `/usr/local/bin/`.
#### Downloading a pre-built bundle
The easiest way to install Geth is by downloading a pre-compiled binary for your operating system.
Follow these steps:
* Go to the official Geth [downloads](https://geth.ethereum.org/downloads) page
* Select your OS (Windows, macOS, Linux).
### Configuration & CLI Flags
Geth is controlled using the **command line**.
To start Geth, use the `geth` command.
To stop Geth, press `ctrl-c`.
Geth can be configured using command-line options called flags.
**Common Flags**
```
--syncmode value – Syncing strategy (snap, full, fast, or light). Default: "snap".
--http - Enable the HTTP-RPC server.
--datadir value – Data directory for the databases and keystore.
--verbosity value – Logging verbosity (0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail).
```
To get command-line help, run:
```
geth --help
```
For a comprehensive list of CLI options, refer to the Geth [Command-Line Options](https://geth.ethereum.org/docs/fundamentals/command-line-options).
## Security
**Security Best Practices**
Securing and maintaining your Geth node is important to ensure the integrity of your operations and the broader Ethereum network. Here are essential security best practices:
* Download Geth using only the links on the [Downloads](https://geth.ethereum.org/downloads) page.
* Avoid exposing Geth API endpoints to the internet.
* Ensure to keep private keys and account passwords backed up and inaccessible to adversaries.
* Make use of [Clef](https://geth.ethereum.org/docs/tools/clef/introduction), a standalone key manager to manage private keys. Clef requires manual approval for transactions, reducing the risk of unauthorized operations.
## Conclusion
By adhering to best practices, such as implementing proper firewall rules, regularly updating software, and securely storing keys, users can maintain a healthy and secure Geth node while contributing seamlessly to Ethereum’s decentralized ecosystem.
For more details, refer to the official Geth [documentation](https://geth.ethereum.org/docs).