Sharing spells for wizards
The Spellbook feature of wizards allows them to expend time and money to copy one another's spells from each others' spellbooks.
When you find a wizard spell of 1st level or higher, you can add it to your spellbook if it is of a spell level you can prepare and if you can spare the time to decipher and copy it.
For each level of the spell, the process takes 2 hours and costs 50 gp.
Wizards can also copy wizard spells from spell scrolls (see the section on Scribing Scrolls below)
Pact of the Tome and Book of Ancient Secrets
Wizards can also copy spells from warlocks who have the Pact of the Tome feature and the Book of Ancient Secrets invocation as long as the ritual spell in the Book of Shadows is a wizard spell.
Warlocks with the Pact of the Tome can copy any ritual spell that appears in either another Book of Shadows, a spellbook, or a spell scroll.
Book of Ancient Secrets
...you can add other ritual spells to your Book of Shadows... if you can spare the time to transcribe the spell. For each level of the spell, the transcription process takes 2 hours and costs 50 gp for the rare inks needed to inscribe it.
The optional downtime rules in Xanathar's Guide to Everything includes the option to scribe spell scrolls which could then be cast by other spellcasters who share that spell on their spell lists. This also takes time and money, and only affords one casting before the scroll is destroyed:
Scribing a spell scroll takes an amount of time and money related to the level of the spell the character wants to scribe, as shown in the Spell Scroll Costs table. In addition, the character must have proficiency in the Arcana skill and must provide any material components required for the casting of the spell. Moreover, the character must have the spell prepared, or it must be among the character’s known spells, in order to scribe a scroll of that spell.
These magic items appear in an adventure module:
Out of the Abyss
A spellcaster attuned to a spell gem can imbue it with a spell.
To do so, you cast the spell while holding the gem. The spell is stored in the gem instead of having any effect. Casting the spell must require either 1 action or 1 minute or longer, and the spell’s level must be no higher than the gem’s maximum.
It can then be cast by anyone who could cast that spell from a scroll or who knows the spell from some other source.
While holding the gem, you can cast the spell from it as an action if you know the spell or if the spell is on your class’s spell list. Doing so doesn’t require any components and doesn’t require attunement.