The saying is from
Thus Spoke Zarathustra: A Book for All and None (German: Also sprach Zarathustra: Ein Buch für Alle und Keinen, also translated as Thus Spake Zarathustra). Much of the work deals with ideas such as the "eternal recurrence of the same", the parable on the "death of God", and the "prophecy" of the Übermensch, which were first introduced in The Gay Science.[2] The central idea of Zarathustra; this idea occurred to him by a
"pyramidal block of stone".
This concept first occurred to Nietzsche while he was walking in Switzerland through the woods along the lake of Silvaplana (close to Surlej); he was inspired by the sight of a gigantic, towering, pyramidal rock. The book chronicles the fictitious travels and speeches of Zarathustra. Zarathustra's namesake was the founder of Zoroastrianism, usually known in English as Zoroaster (Avestan: Zaraϑuštra). Nietzsche is clearly portraying a "new" or "different" Zarathustra,
one who turns traditional morality on its head. He goes on to characterize "what the name of Zarathustra means in my mouth, the
mouth of the first immoralist. "Zarathustra also contains the
famous dictum "God is dead", which had appeared earlier in The Gay Science.[5] The book's underlying concept is
the eternal recurrence of the same events. (side note: Eternal return (also known as eternal recurrence) is a theory that the universe and all existence and energy has been recurring, and will continue to recur, in a self-similar form an infinite number of times across infinite time or space. Eternal return is based on the philosophy of pre-determinism in that people are predestined to continue repeating the same events over and over again.)
The excerpt:
https://www.theperspectivesofnietzsche.com/nietzsche/nuber.html
"I teach you the overman. Man is something that shall be overcome. What have you done to overcome him?
All beings so far have created something beyond themselves; and do you want to be the ebb of this great flood and even go back to the beasts rather than overcome man? What is the ape to man? A laughingstock or a painful embarrassment. And man shall be just that for the overman: a laughingstock or a painful embarrassment...
Behold, I teach you the overman. The overman is the meaning of the earth.Let your will say: the overman shall be the meaning of the earth! I beseech you, my brothers, remain faithful to the earth, and do not believe those who speak to you of otherworldly hopes! Poison-mixers are they, whether they know it or not. Despisers of life are they, decaying and poisoned themselves, of whom the earth is weary: so let them go.
Once the sin against God was the greatest sin; but God died, and these sinners died with him. To sin against the earth is now the most dreadful thing, and to esteem the entrails of the unknowable higher than the meaning of the earth...
What is the greatest experience you can have? It is the hour of the great contempt. The hour when your happiness, too, arouses your disgust, and even your reason and your virtue.
The hour when you say, 'What matters my happiness? It is poverty and filth and wretched contentment. But my happiness ought to justify existence itself.'
The hour when you say, 'What matters my reason? Does it crave knowledge as the lion his food? It is poverty and filth and wretched contentment.'
The hour when you say, 'What matters my virtue? As yet it has not made me rage. How weary I am of my good and my evil! All that is poverty and filth and wretched contentment.'
"Man is a rope, tied between beast and overman--a rope over an abyss...
What is great in man is that he is a bridge and not an end: what can be loved in man is that he is an overture and a going under...
"
I say unto you: one must still have chaos in oneself to be able to give birth to a dancing star. I say unto you: you still have chaos in yourselves.
Alas, the time is coming when man will no longer give birth to a star. Alas, the time of the most despicable man is coming, he that is no longer able to despise himself. Behold, I show you the last man.
'What is love? What is creation? What is longing? What is a star?' thus asks the last man, and blinks.
The earth has become small, and on it hops the last man, who makes everything small. His race is as ineradicable as the flea; the last man lives longest.
'We have invented happiness,'say the last men, and they blink. They have left the regions where it was hard to live, for one needs warmth. One still loves one's neighbor and rubs against him, for one needs warmth...
One still works, for work is a form of entertainment. But one is careful lest the entertainment be too harrowing. One no longer becomes poor or rich: both require too much exertion. Who still wants to rule? Who obey? Both require too much exertion.
No shepherd and one herd! Everybody wants the same, everybody is the same: whoever feels different goes voluntarily into a madhouse.
'Formerly, all the world was mad,' say the most refined, and they blink...
One has one's little pleasure for the day and one's little pleasure for the night: but one has a regard for health.
'We have invented happiness,' say the last men, and they blink."
from Nietzsche's Thus spoke Zarathustra, p.3,4,5, Walter Kaufmann transl.