This is Fredric Brown's Something Green.
Here's a blog post about the story.
The story was about a man who crashed on a uninhabited planet and was wandering around for few years looking for another crashed spaceship to use it's parts to repair his spaceship. He had a small alien creature sitting on his shoulder with who he talked about Earth and how he wants to return home.
He said, “Here we go, Dorothy. All set?”
The little five-limbed creature that rested on his shoulder didn't
answer, but then it never did. It couldn't talk, but it was something
to talk to. It was company. In size and weight it felt amazingly like
a hand resting on his shoulder.
He'd had Dorothy for -- how long? At a guess, four years. He'd been
here about five, as nearly as he could reckon it, and it had been
about a year before he'd found her. Anyway, he assumed that Dorothy
was of the gentler sex, if for no better reason than the gentle way
she rested on his shoulder, like a woman's hand.
McGary chuckled softly. “Did you see that, Dorothy? That was green,
the one color you don't have on this bloody red planet of yours. The
most beautiful color in the universe, Dorothy. Green! And I know where
there's a world that's mostly green, and we're going to get there, you
and I. Sure we are. It's the world I came from, and it's the most
beautiful place there is, Dorothy. You'll love it.”
Pilot told the protagonist that he actually was stuck on this planet for decades, the spaceship he was looking for crashed on a different planet, there is no alien creature on his shoulder he was imagining it, the Earth is no more and people now live on Mars (?). At the end man shot the pilot and continued wandering around and talking to the imaginary alien creature.
You've done wonderfully for thirty years, McGarry. You can thank God
for the fact that you believed Marley's spacer crashed on Kruger III;
it was Kruger IV. You'd have never found it here, but the search, as
you say, kept you -- reasonably sane.” He paused a moment. His voice
was gentle when he spoke again. “There isn't anything on your
shoulder, McGarry. This Dorothy is a figment of your imagination. But
don't worry about it; that particular delusion has probably kept you
from cracking up completely.”
Lieutenant Archer was shaking his head slowly. Not back to Earth,
old-timer. To Mars if you wish, the beautiful brown and yellow hills
of Mars. Or, if you don't mind heat, to purple Venus. But not to
Earth, McGarry. Nobody lives there anymore.”
The war with the Arcturians, twenty years ago. They
struck first, and got Earth. We got them, we won, we exterminated
them, but Earth was gone before we started. I'm sorry, but you'll have
to settle for somewhere else.
McGarry's sol-gun came out of its holster. McGarry shot him, and
Lieutenant Archer wasn't there anymore. McGarry stood up and walked to
the little spacer. He aimed the sol-gun at it and pulled the trigger.
Part of the spacer was gone. Half a dozen shots and it was completely
gone. Little atoms that has been the spacer and little atoms that had
been Lieutenant Archer of the Space Patrol may have danced in the air,
but they were invisible.