Before start, make sure your device has a bluetooth interface or else get a cheap USB bluetooth dongle.

Install bluetooth from apt.

$ sudo apt install bluetooth

This will install bluetoothctl and bluetoothd.
Start the bluetooth service.

$ sudo service bluetooth start
$ sudo bluetoothctl
[bluetooth] agent on
[bluetooth] default-agent
[bluetooth] scan on
[bluetooth] devices
[bluetooth] pair <bluetooth_mac_address>

If you're pairing a bluetooth keyboard, it will show a key to pair the keyboard. Type that key using the bluetooth keyboard and press enter key to get paired. Finally, enter command connect to establish the connection with the bluetooth device.

[bluetooth] connect <bluetooth_mac_address>