# Installation

These XState v4 docs are no longer maintained

XState v5 is out now! Read more about XState v5 (opens new window)

🆕 Find more about installing XState (opens new window) in our new docs.

You can install XState from NPM or Yarn, or you can embed the <script> directly from a CDN.

# Package Manager

npm install xstate@latest --save
# or:
yarn add xstate@latest --save

# CDN

You can include XState directly from the unpkg CDN (opens new window):

<script src="https://unpkg.com/xstate@4/dist/xstate.js"></script>

The variable XState will be available globally, which will give you access to the top-level exports.

const { createMachine, actions, interpret } = XState; // global variable: window.XState

const lightMachine = createMachine({
  // ...
});

const lightService = interpret(lightMachine);
Last Updated: 3/15/2024, 12:45:01 PM