If you are using Linux as your OS of choice, chances are GnuPG is already installed. If not, follow your distributions way of adding additional software. Same goes in case of macOS.
Alternatively, download the appropriate version from the download section and follow the install instructions.
gpg --gen-key gpg (GnuPG) 2.0.22; Copyright (C) 2013 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? 1
RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) 4096 Requested keysize is 4096 bits
Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 1y # Double check expiration according to your validity choice Key expires at Tue 04 Jul 2017 07:57:46 PM CEST Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key. Real name: John Doe Email address: firstname.lastname@example.org Comment: This indeed is my key!
You selected this USER-ID: "John Doe (This indeed is my key!) <email@example.com>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
Enter passphrase Passphrase ***************_________________________ <OK> <Cancel>
Please re-enter this passphrase Passphrase ***************_________________________ <OK> <Cancel>
We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
gpg: key AA6CFB50 marked as ultimately trusted public and secret key created and signed. gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 5 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 5u gpg: next trustdb check due at 2017-07-04 pub 4096R/AA6CFB50 2016-07-04 [expires: 2017-07-04] Key fingerprint = 6279 69BF 8644 4D64 CA63 1F55 962C 1715 AA6C FB50 uid [ultimate] John Doe (This indeed is my key!) <firstname.lastname@example.org> sub 4096R/109F9230 2016-07-04 [expires: 2017-07-04]
Make sure you upload your public key to a key-server so it can be used for verifications.