Then Judah said to Onan, “Go in to your brother's wife and perform the duty of a brother-in-law to her, and raise up offspring for your brother.”
Genesis 38:8

The story of Judah and Tamar shows that the levirate practice predates Sinai and the written #torah, as do all of God's rules. In a levirate marriage, if one brother was married and died with no children, his next brother was required to marry his widow. For all legal purposes, the first son from that marriage would be considered the son and heir of the deceased brother. If the man had no full brothers, the duty would fall on the next closest male relative, other than his father.