Initialize your IPFS Repository

Initialize your IPFS Repository

In this lesson we are going to:

If you don't have IPFS installed on your device, then install it first.

Initialize the Repository

Use the ipfs init command to initialize the IPFS repository. This will generate a local IPFS repository for the current user account on your machine. It also generates a cryptographic keypair that allows your IPFS node to cryptographically sign the content and messages that you create.

$ ipfs init

initializing IPFS node at /home/vasa/.ipfs
generating 2048-bit RSA keypair...done
peer identity: Qmcpo2iLBikrdf1d6QU6vXuNb6P7hwrbNPW9kLAH8eG67z
to get started, enter:

ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

The hash after "peer identity: <HASH>" is your node’s ID and will be DIFFERENT from the one shown in the above output. Other nodes on the network use it to find and connect to you. You can run ipfs id at any time to get it again if you need it.

Note: If you have already initialized ipfs on your machine, you will get an error message like:
$ ipfs init

initializing IPFS node at /home/vasa/.ipfs
Error: ipfs configuration file already exists!
Reinitializing would overwrite your keys.

This is ok. It means you've already done this step. You can safely proceed to next step.

If you are running on a server in a data center, you should initialize IPFS with the server profile. This will prevent IPFS from creating a lot of data center-internal traffic trying to discover local nodes:
$ ipfs init --profile server

There are a whole host of other configuration options you may want to set — check the full reference for more.

Use IPFS to explore the post-install documentation
If you installed a different version of ipfs, you may have gotten a slightly different path to use here. Either path will work for this tutorial. The path you got from the ipfs init command will give you documentation that's accurate for the version of ipfs you're using.

When you ran ipfs init, it provided a hint for how you can get started. It said:

to get started, enter:


ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

This ipfs cat command tells ipfs to read the content matching the path you provided. If the content isn't available locally, ipfs will attempt to find it on the peer-to-peer network.

Run the ipfs cat command with the path you got from the init message:

$ ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

You should see something like this:

Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗  ███████╗
██║██╔═══╝ ██╔══╝  ╚════██║
██║██║     ██║     ███████║
╚═╝╚═╝     ╚═╝     ╚══════╝


If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

--------------------------------------------------------
| Warning:                                             |
| This is alpha software. use at your own discretion!  |
| Much is missing or lacking polish. There are bugs.   |
| Not yet secure. Read the security notes for more.    |
--------------------------------------------------------

Check out some of the other files in this directory:


./about
./help
./quick-start       <-- usage examples
./readme            <-- this file
./security-notes

You can explore other objects in there. For example, check out quick-start:

$ ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/quick-start
Locate where IPFS Stores the Repository Contents on your Machine

ipfs stores its local object repository in ~/.ipfs

$ ls ~/.ipfs

The contents of that directory look something like this:

blocks   config   datastore   datastore_spec   keystore   version

All of the contents of your IPFS repository are stored within this directory. For example, the readme file from above is stored in here, along with the other files it links to.

The Repo stores a collection of IPLD objects that represent:

  • config - Node configuration and settings. We will learn more about config file below.
  • datastore - Content stored locally, and indexing data.
  • datastore_spec - Array of mounting points and their properties.
  • keystore - Cryptographic keys, including node's identity.
  • version - The repo version, required for safe migrations.
  • blocks - It contains blobs containing binary data.
Open the IPFS Configuration file

The configuration for your ipfs repository is in a JSON file that's usually stored at ~/.ipfs/config. To view the current config, run:

$ ipfs config show

One of the useful details in this config file is at Datastore.Path. This tells you where the ipfs repository's contents are being stored. As we saw above, this is usually ~/.ipfs

If you want to learn more about the contents of the config file, then head here.

Next Steps

In the next lesson, we will connect our IPFS node with other IPFS nodes on the public network.

Subscribe to SimpleAsWater

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe