A General Overview of the Seven Commandments
G-d gave the first six commandments to Adam when he was created in the Garden of Eden. These commandments were repeated, and a 7th commandment was added, when G-d made the Covenant of the Rainbow with Noah and all of the world’s creatures. Hence these became known as the Seven Noahide Commandments.
The entire Book of Genesis, and the Book of Exodus up to and including the arrival of the Israelites at Mt. Sinai, were dictated by G-d to Moses when they arrived there. There was then a first covenant made between G-d and the Israelites on that part of the Torah, which included their acceptance of the Seven Noahide Commandments which are for all nations. That was four days before the Ten Commandments (which implicitly included all the 613 Jewish Commandments) were spoken openly by G-d to all of the Israelites (approximately 3 million people.
Since the whole future existence of the creation was dependent on the acceptance of the Torah of Moses and its 613 Jewish Commandments by the Israelites at Mt. Sinai, G-d’s covenant for the reward of eternal life was made on the Torah at that time as a heritage for the Jews, and for Gentiles who wish to accept their part in this Mosaic Covenant. The Torah is G-d’s “Tree of Eternal Life,” and from that time on, Gentiles can obtain a share in the future World to Come (the culmination of the Messianic Era) if they choose to observe their part in the Written Torah and Oral Torah which G-d gave through Moses.
The part of Torah that G-d decreed for Gentiles to observe is the Seven Noahide Commandments (which in essence are all prohibitions). G-d told Moses at Mount Sinai that Gentiles (“all that come into the world”) should keep those Seven Commandments, according to their details that G-d taught to Moses in the Oral Torah. These details are the foundation of the Noahide Code.
G-d also made this understandable by simple human logic. Since we only know about the Seven Noahide Commandments and all their details through G-d’s Torah, a Noahide’s reward for acceptance and fulfillment of them as Divine Commandments must be accompanied by faith in the Torah. But if a person lacks this faith, G-d forbid, that does not change his or her accountability for transgression of any of the Seven Noahide Commandments.
Note that the Covenant of the Rainbow was not dependent on these commandments. Rather it was G-d’s promise to all living creatures that He would never again obliterate all land-life from the world, no matter how sinful people would become (Genesis 9:8-17 – “Never again will there be a flood to destroy the earth”). The Covenant of the Rainbow has an inner meaning as well, which is that G-d promised that He would always accept a person’s sincere personal repentance if it was directed to Him.
The Universal Message
When G-d renewed these universal commandments with Noah (see beginning of Genesis ch. 9), they were meant not just for Noah and his immediate family, but for all of Noah’s descendents (i.e. all nations, for all time) as G-d’s basis for civilized human society.
At Mount Sinai, when G-d told Moses to record the Noahide Commandments and the story of Noah in the first book of the Torah (Genesis), He commanded through Moses that these seven commandments should be learned and practiced by all the nations for all time, according to their details which would be revealed in the Torah (G-d’s “Tree of Eternal Life”), and that that this would be the opportunity through which Gentiles can merit to receive a place in the eternal future World to Come.
From various narratives in Genesis, we also learn that a wide variety of peoples knew about and either practiced or were held responsible for the Noahide Commandments: the Chaldeans (as demonstrated by Abraham, who was alive for many years before Noah passed away), the Philistines (as demonstrated by Abimelech), the Hivvites (as demonstrated by the story of Shechem), and the Canaanites (as demonstrated by the story of Sodom and Gomorrah).