Step 1. Back up your wallet. You are messing with your wallet here, ... and it is easy to do things you might not have intended.
Run Bitcoin as a server, e.g.,
$ ./bitcoin-qt -server
then launch another shell / terminal window.
If you've encrypted your wallet you'll need to open it for RPC
$ ./bitcoind walletpassphrase [passphrase] 1000
then
$ ./bitcoind importprivkey
then close bitcoin-qt.
then
$ ./bitcoind -rescan