Write "goodbye."
"Goodbye" and "good-bye" are the same. "Good bye" is incorrect. "Good-bye" appears in old books but it's out of date.
Sometimes spellings change slowly over time. There has been a trend to uses fewer and fewer hyphens and to spell more and more compound words as single words, without hyphens.
The general rule is simple: check a dictionary.
An interesting example is the word "cooperate." That's the current, correct spelling. A problem is that it looks as if you'd pronounce "coop-" as one syllable, like the word "coop." In very old books they put a dieresis over the second "o," "coöperate," to show that you pronounce it as two syllables, one of the very rare uses of a diacritical mark in English. Then they began spelling it "co-operate." Finally they dropped the hyphen, and began spelling it as "cooperate," and you just have to know how it is pronounced.