Space.com explains that similar to other planets of the solar system, Jupiter is considered to have formed through the process known as core accretion. Other theories attempt to resolve problems that occur in the core accretion model, such as the rapid formation of gas planets. The disk instability model, which is a relatively new theory, allows for the faster formation of planets.
NASA explains that Jupiter must have formed early in the process of the formation of the solar system because it is composed mostly of helium and hydrogen, similar to the sun. It appears that Jupiter captured most of the remaining material after the collapse of the nebula, giant cloud of dust and gas, and the formation of the sun. In order to retain the light gases, Jupiter must have formed quickly. Otherwise, the solar winds would have pushed the gases away from the planet. The disk instability model theorizes that clumps of these gases and dust particles bound together in the early solar system, and gradually compacted to form giant planets, according to Space.com.
Presently, it is unclear whether an early formation of a massive planetary core helped in capturing the gases because of the gravitational force, or an unstable region inside the nebula collapsed and triggered the formation of the planet. Formation of planets through core accretion takes many million years. The light gases were not available in the early solar system for this long.