In this how to tutorial, Let’s see how to install Bitcoin daemon wallet on a Ubuntu server.
Basic Requirements for bitcoin installation on ubuntu server:
- Minimum OS required – Ubuntu 16.04 OS
- Space required – minimum 400 GB. SSD hard disk recommended.
- RAM – Minimum 4GB ram server is required.
1. Install Apache
Make sure you have installed Apache or nginx on your server before starting with the installation. Type the below commands to install Apache on ubuntu server:
sudo apt-get update
sudo apt-get install apache2
You will be requested to enter Y/N. Type Y to proceed with the installation
2. Installing Bitcoin Blockchain
Download PPA repository by running the below command from home/root directory (Type cd ~ )
sudo add-apt-repository ppa:luke-jr/bitcoincore
When prompted, click ENTER key to proceed with the installation.
sudo apt-get update
sudo apt-get install bitcoind
When prompted, type Y to proceed with the installation.
3. Setting up Bitcoin Configuration
A. Creating .bitcoin folder in root directory.
Run the following command to check if you are in the root directory:
Then run the following command to create the .bitcoin directory. For starters: mkdir stands for make directory. And and dot folder means it is a hidden folder. You can not view the folder normally with ls command and you need to use ls-a command to view the hidden folder.
change or move into the newly created directory using the below command:
B. Setting config file
Creating the config file. In this tutorial i am using nano editor in ubuntu. You can also use vi editor if you wish. Run the below command to create the file:
sudo nano bitcoin.conf
You will see an editor like in the below screenshot:
Copy the below configuration and paste it in the text editor:
server=1 rpcport=18523 rpcallowip=ip_address_of_your_external_application/0 rpcuser=yokesh_explains testnet=1 rpcpassword=32_character_alphanumeric_string
and click ctrl+X. Prompt will ask you to save and exit. Type Y and hit enter. Your configuration file is saved now.
Let’s see about these configurations now.
- Server = 1 or 0 means -> Bitcoin server to accept JSON-RPC command or Not. 1 Stands for accepting.
- rpcport -> This is the tcp port which we setup for allowing rpc connections
- rpcuser -> An username will be required to setup for accessing the JSON-RPC Apis.
- rpcpassword -> Similarly a password will be required to setup for accessing the JSON-RPC Apis. The RPC Password can be any random alphanumeric number. 32 character is recommend for security purposes. You can generate one from HERE.
- testnet=1 -> If enabled as 1, the bitcoin network will access the bitcoin testnet network. If entered as 0 or if the config is removed, by default the bitcoind will connect to the mainnet. Connecting to bitcoin testnet will be helpful for testing purposes.
There are more configurations which you can do. Lets see more in detail about it in upcoming articles.
C. Setting up Firewall
Run the below commands to open the required ports and to turn on ubuntu default firewall.
Enabling SSH port with Firewall –
sudo ufw allow 22
Enabling HTTP port with Firewall –
sudo ufw allow 80
Enabling HTTPS port with Firewall –
sudo ufw allow 443
Enabling our RPC port with Firewall. make sure you give the same port number as you have given in conf file.
sudo ufw allow 18523
Finally enable Firewall –
sudo ufw enable
D. Configuring Cron
Run the below command to make sure bitcoind continues to run when server is restarted:
sudo crontab -e
Type 1 and hit enter. Next in the editor goto the last and paste it in a new line.
@reboot bitcoind -daemon
Finally the setup is now done. Lets start the bitcoin server and access the wallets.
4. Starting Bitcoin Blockchain
Run the below daemon command to initialize bitcoin blockchain in background:
We will have to wait for the blockchain to complete downloading and sync with the current block to send and receive transactions. The blocks and headers number will be equal in numbers when the blockchain is downloaded and in sync.
Use the below JSON-RPC commands to interact with the bitcoin blockchain:
- bitcoin-cli getblockchaininfo -> Gives complete detail of the blockchain status
- bitcoin-cli getwalletinfo -> Gives complete detail of the wallet – balance etc.
- bitcoin-cli getnewaddress -> Creates a new address.
Complete of bitcoin-cli commands can be found from HERE
Note that when you do getblockchaininfo, you see that the blocks and headers are not in sync initially
Alright! You are all ready now. You have successfully completed bitcoin installation on ubuntu server successfully. Let me know in comments if you face any issue in the above steps.