{"_id":"5bf2f085477ed90031618789","project":"54cf411f9d09bb0d00a17a1c","version":{"_id":"54cf411f9d09bb0d00a17a1f","project":"54cf411f9d09bb0d00a17a1c","__v":16,"createdAt":"2015-02-02T09:19:27.656Z","releaseDate":"2015-02-02T09:19:27.656Z","categories":["54cf41209d09bb0d00a17a20","54cfb99bbba1a023008741af","54cfb9a65ff7e617002bbd7f","54cfba03bba1a023008741b6","54cfba0ebba1a023008741b8","54cfba19bba1a023008741b9","54cfba29bba1a023008741bb","54cfba345ff7e617002bbd87","54cfba3ebba1a023008741bc","54cfba473995cf0d0006f6f0","54e371b18ef7552300409bf2","54e37aa5e887c50d005ef629","555a4e9b147f91190092d137","56b0e91802f4bc0d006ce254","5bb4f4e01635b500032b94fd","5c05a785ceb5b80220cf0e93"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"5c05a785ceb5b80220cf0e93","project":"54cf411f9d09bb0d00a17a1c","version":"54cf411f9d09bb0d00a17a1f","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2018-12-03T22:00:37.979Z","from_sync":false,"order":8,"slug":"migrating-to-offline","title":"Migrating to Offline"},"user":"5bac0709475b5d000364fa42","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-11-19T17:19:01.457Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"You can use Cloud9 to work with code offline on your local desktop or laptop computer by using a special edition of Cloud9 named *Cloud9 Core*. Cloud9 Core uses the Node.js runtime and web browser running on your local computer to display an offline integrated development environment (IDE) that works similar to its c9.io and AWS Cloud9 online counterparts.\n\nTo use Cloud9 Core, we recommend using one of the following options, which we present in order of increasing time and complexity to set up:\n\n* [Option A: Run Cloud9 Core directly](using-cloud9-core#section-option-a-run-cloud9-core-directly)\n* [Option B: Run Cloud9 Core in a new Docker container](using-cloud9-core#section-option-b-run-cloud9-core-in-a-new-docker-container)\n* [Option C: Run Cloud9 Core in an existing Docker container](using-cloud9-core#section-option-c-run-cloud9-core-in-an-existing-docker-container)\n\n:exclamation: **The information in this topic is not fully supported by Cloud9 or AWS. Use it at your own risk.** We have not fully tested the following information with all operating systems, and we can't guarantee it will work in all situations. Be sure to back up your folders, files, and data, so that you can re-create them, if needed. \n\n:question: If you have questions or need help with Cloud9 Core, go to the [Cloud9 Community](https://community.c9.io/) website or email [support:::at:::c9.io](mailto:support@c9.io).\n\n# Option A: Run Cloud9 Core directly\n\nIn this approach, you install and then run Cloud9 Core directly on your local computer. When you run Cloud9 Core, you point it to an existing directory (and its subdirectories structure) on your local computer to display in the IDE's **Workspace** window. You then use a web browser on your local computer to display the Cloud9 Core IDE. \n\n:information-source: To use Cloud9 Core to to work with code that's inside of a Docker container, see [Option B](using-cloud9-core#section-option-b-run-cloud9-core-in-a-new-docker-container) or [Option C](using-cloud9-core#section-option-c-run-cloud9-core-in-an-existing-docker-container).\n\n## Prerequisites\n\n1. Ensure that the Node.js runtime is installed. To check, from a terminal or command prompt on your local computer, run the command `node --version`. If the Node.js version number isn't displayed, see the following to install Node.js:\n\n    * **macOS**: [Installing Node.js via package manager: macOS](https://nodejs.org/en/download/package-manager/#macos) or [Installing Node.js Tutorial: macOS](https://nodesource.com/blog/installing-nodejs-tutorial-mac-os-x/)\n    * **Windows**:  [Installing Node.js via package manager: Windows](https://nodejs.org/en/download/package-manager/#windows) or [Installing Node.js Tutorial: Windows](https://nodesource.com/blog/installing-nodejs-tutorial-windows/)\n    * **Linux**: [Installing Node.js via package manager](https://nodejs.org/en/download/package-manager/)\n\n2. Ensure that Git is installed. To check, from a terminal or command prompt on your local computer, run the command `git --version`. If the Git version number isn't displayed, install Git by following the steps in [Installing Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).\n\n## Step 1: Download and install the Cloud9 Core\n\n1. From a terminal or command prompt on your local computer, switch to the directory where you want to download Cloud9 Core. This can be any directory that's convenient for you, for example `~`. \n\n    :information-source: For Windows, `~` is available through utilities such as [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/setup/starting-windows-powershell) and [Git Bash for Windows](https://gitforwindows.org/). Or you can use something like `<drive>:\\Users\\<user_name>\\`.\n\n2. Run the following commands, one at a time, to download and then install Cloud9 Core into the current directory.\n\n    :information-source: For Windows, we recommend running the following commands by using utilities such as PowerShell or Git Bash for Windows, instead of the built-in **Command Prompt** utility. This is because **Command Prompt** can't run `.sh` files by default.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"git clone https://github.com/c9/core.git c9sdk\\ncd c9sdk\\nscripts/install-sdk.sh\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n## Step 2: Run Cloud9 Core\n\n1. From the `c9sdk` directory in the previous Step 1, run the following command to start Cloud9 Core.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"node server.js -w <starting_directory_path> -a : -l 0.0.0.0 -p 5050\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the preceding command:\n\n* `-w` is the relative or absolute path to any existing directory (and its subdirectories tree) to display in the IDE's **Workspace** window. For example, instead of `<starting_directory_path>`, this could be `/Users/<user_name>/` for macOS, `c:\\Users\\<user_name>\\` for Windows, or `/home/<user_name>/` for Linux. \n* `-a` is the basic auth name and password to use when starting Cloud9 Core, in this case, `:` means don't use any name or password.\n* `-l` is the IP address for Cloud9 Core to run on, in this case, `0.0.0.0`.\n* `-p` is the port for Cloud9 Core to run on, in this case, `5050`. If port 5050 is already being used on your local computer, change it to a different port.\n\n2. Use your local computer's web browser to go to `http://127.0.0.1:5050/`, which displays the Cloud9 Core IDE. (If you changed `5050` in the preceding command, change it here also.)\n\n    :information-source: To display a different directory in the IDE's **Workspace** window, you must stop Cloud9 Core and then restart it with a different `-w` value. To stop Cloud9 Core, you can close the running command's containing window, or you can simply use your operating system's shortcut key combination for stopping the current running command (for example **Ctrl+C** or **Ctrl+X**). If you stop Cloud9 Core, the IDE also stops working. After you restart Cloud9 Core, refresh your web browser to restart the IDE. \n\n# Option B: Run Cloud9 Core in a new Docker container\n\nIn this approach, you use Docker to create a Docker image that contains Cloud9 Core. You run a Docker container based on that image. Then you use a web browser on your local computer to display the Cloud9 Core IDE. \n\n:information-source: To use Cloud9 Core to work with code that's inside of an existing running Docker container, see [Option C](using-cloud9-core#section-option-c-run-cloud9-core-in-an-existing-docker-container).\n\n## Prerequisites\n\n1. Install Docker. For instructions, see [Install Docker](migrating-to-cloud9-offline#section-step-2-install-docker) in *Migrating a Workspace to Offline*, and then return to this section.\n2. Start Docker. For instructions, see [Start Docker](migrating-to-cloud9-offline#section-step-3-start-docker) in *Migrating a Workspace to Offline*, and then return to this section.\n\n:exclamation: To run a new Docker container that contains a special version of Cloud9 Core with Harvard's CS50-specific plugins, skip the rest of this topic and see [CS50 IDE Offline](https://cs50.readthedocs.io/ide/offline/) instead.\n\n## Step 1: Create a Docker image\n\nIn this step, you create a [Dockerfile](https://docs.docker.com/engine/reference/builder/), which is a text file that describes what Docker needs to create a Docker [image](https://docs.docker.com/engine/docker-overview/#docker-objects). This particular image includes Cloud9 Core. You can also add to this image the settings, packages, apps, and dependencies from one of the default c9.io online workspace types. Once you have a Dockerfile, you can use it to create the image.\n\n1. We recommend creating a blank directory to put the Dockerfile into. For example, this section uses `~/Docker/`. \n\n    :information-source: For Windows, `~` is available through utilities such as [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/setup/starting-windows-powershell) and [Git Bash for Windows](https://gitforwindows.org/). Or you could use something like `<drive>:\\Users\\<user_name>\\Docker\\`.\n\n2. In the blank directory that you created, open a text editor and create a file named `Dockerfile` (with no extension). Add the following contents to this file, and then save it.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# Replace cloud9/ws-php with any existing Ubuntu-based Docker image ID you want.\\nFROM cloud9/ws-php\\n\\n# Use default answers for all setup prompts.\\nENV DEBIAN_FRONTEND noninteractive\\n\\n# Remove any default PHP debugging settings. \\n# Also remove any default workspace files, as they might be replaced later. \\nRUN rm -rf /etc/php5/mods-available/xdebug.ini /home/ubuntu/workspace/*\\n\\n# Add Ruby Version Manager (rvm) to PATH.\\nENV PATH=\\\"/usr/local/rvm/bin/:$PATH\\\"\\n\\n# Set ownership defaults.\\nRUN chown -R ubuntu:ubuntu /home/ubuntu\\n\\n# Install Node.js.\\nRUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \\\\\\n    apt-get install nodejs -y\\n\\n# Populate environment variables that are required by Cloud9 Core.\\nRUN echo \\\"export USER=ubuntu\\\\n\\\\\\nexport C9_PROJECT=c9-offline\\\\n\\\\\\nexport C9_USER=ubuntu\\\\n\\\\\\nexport C9_HOSTNAME=\\\\$IP\\\\n\\\\\\nexport C9_PORT=\\\\$PORT\\\\n\\\\\\nexport IDE_OFFLINE=1\\\\n\\\\\\nalias c9=/var/c9sdk/bin/c9\\\" >/etc/profile.d/offline.sh\\n\\nUSER ubuntu\\n\\n# Download Cloud9 Core into the Docker container.\\nWORKDIR /var\\nRUN sudo rm -rf c9sdk && \\\\\\n    sudo mkdir c9sdk && \\\\\\n    sudo chown ubuntu:ubuntu c9sdk && \\\\\\n    git clone https://github.com/c9/core.git c9sdk\\n\\n# Install Cloud9 Core within the Docker container.\\nWORKDIR c9sdk\\nRUN scripts/install-sdk.sh\\n\\n# Set additional ownership defaults.\\nRUN sudo chown -R ubuntu:ubuntu /home/ubuntu/workspace/ && \\\\\\n    sudo chown -R ubuntu:ubuntu /home/ubuntu/.c9/\\n\\n# Have the Docker container listen to these ports at run time.\\nEXPOSE 5050 8080 8081 8082\\n\\n# Run Cloud9 Core within the Docker container.\\nENTRYPOINT [\\\"node\\\", \\\"server.js\\\", \\\\\\n            \\\"-w\\\", \\\"/home/ubuntu/workspace\\\", \\\\\\n            \\\"--auth\\\", \\\":\\\", \\\\\\n            \\\"--listen\\\", \\\"0.0.0.0\\\", \\\\\\n            \\\"--port\\\", \\\"5050\\\"]\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n3. In the preceding Dockerfile, replace the following code, and then resave the file:\n\n    * Replace `cloud9/ws-php` in line 2 with the ID of any existing Ubuntu-based Docker image you want. (It must be an Ubuntu-based image, because this Dockerfile uses Ubuntu-based commands.) For a list of images that represent available default c9.io online workspace types (which are all Ubuntu-based), see the table of base image IDs in [Run the Container](migrating-to-cloud9-offline#section-step-5-run-the-container) in *Migrating a Workspace to Offline*.\n    * If port `5050` is already in use on your local computer, replace `5050` in the last line with any unused port on your local computer. \n\n4. Run the following command to build the image.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker build --no-cache -t myc9image:tag_name .\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the preceding command:\n\n* `--no-cache` means don't use caching when building the image.\n* `-t` is a name and optionally a tag for the image. For example, this topic uses `myc9image` as the image's name and `tag_name` as the image's tag. You can use any name and tag you want, but the image's name and tag combination must be unique on your local computer.\n* `.` (a dot) is the path to the Dockerfile, relative to the current directory. In this case, `.` means the current directory.\n\n:information-source: On Linux, you might need to add `sudo` before `docker`. To get around this, see [Manage Docker as a non-root user](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user).\n\nBuilding the image can take a long time. After the command completes, to confirm that your image was successfully built, run the command `docker image ls`. If successful, you'll see an image in the list with a **REPOSITORY** value of **myc9image** and a **TAG** value of **tag_name**.\n\n## Step 2: Run a new Docker container\n\nIn this step, you use Docker to run a Docker [container](https://docs.docker.com/engine/docker-overview/#docker-objects) that's based on the Docker image you created in the previous Step 1. \n\nFrom a terminal or command prompt on your local computer, run the following command to run the container.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker run --privileged -e \\\"IP=127.0.0.1\\\" -e \\\"PORT=8080\\\" --name myc9ws --mount type=bind,source=<source_path>,target=/home/ubuntu/workspace/ -d -t -p 5050:5050 -p 8080-8082:8080-8082 myc9image:tag_name\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the preceding command: \n\n* `--privileged` gives the container permission to do almost everything that the host operating system can do.\n* `-e` sets simple environment variables in the container, in this case, the IP address and port.\n* `--name` is a name for the container.\n* The optional `--mount` option makes a directory available to the container. `source` is the path to the directory on the host operating system (for example, `<source_path>` could be `/Users/<user_name>/` for macOS, `c:\\Users\\<user_name>\\` for Windows, or `/home/<user_name>/` for Linux). `target` is the path in the container that you can use to refer to that same directory (for example, `/home/ubuntu/workspace/`).\n* `-d` means to run the container in the background.\n* `-t` means to run the container with a pseudo terminal.\n* `-p` connects ports in the container to ports on the host operating system. If you replaced `5050` in your Dockerfile, replace `5050:5050` with the replacement port. For example, if you used `9000` in the Dockerfile, use `9000:9000` here.\n* `myc9image:tag_name` is the name and optional tag of the base image ID to use, which you created in the previous step. \n\nTo confirm that the container is indeed running, run the command `docker ps`. If it's running, you'll see a container with a **NAMES** value of **myc9ws** and a **STATUS** of **Up** in the list of containers. \n\nIf it isn't running, try running the command `docker start myc9ws`, and then run `docker ps` again. \n\nTo see a list of all available containers, regardless of status, run `docker ps -a`.\n\n## Step 3: Run the Cloud9 Core IDE\n\nUse your local computer's web browser to go to `http://127.0.0.1:5050/`, which displays the Cloud9 Core IDE. If you replaced `5050` in the Dockerfile and the `docker run` command, use the replacement port here. \n\n:information-source: To display a different directory in the IDE's **Workspace** window, you must create a separate image, specifying a different `-w` value in the Dockerfile, and then run a separate container based on that image. Also, if you stop a container that's running Cloud9 Core, the IDE also stops working. After you start or restart a container that's running Cloud9 Core, refresh your web browser to restart the IDE. \n\n## Step 4: Commit changes to the running Docker container as you work\n\nIf you stop a container, or if the host operating system stops the container for some other reason, any uncommitted changes that you made to that container will be lost. \n\nTo save your changes as you work, you should commit those changes to a new container. For instructions, see [Save new workspace changes as you work](migrating-to-cloud9-offline#section-step-6-save-new-workspace-changes-as-you-work) in *Migrating a Workspace to Offline*. \n\n# Option C: Run Cloud9 Core in an existing Docker container\n\nIn this approach, you download, install, and run Cloud9 Core in an existing running Docker container. You then use a web browser on your local computer to display the Cloud9 Core IDE. \n\n## Prerequisites\n\n1. Install Docker. For instructions, see [Install Docker](migrating-to-cloud9-offline#section-step-2-install-docker) in *Migrating a Workspace to Offline*, and then return to this section.\n2. Start Docker. For instructions, see [Start Docker](migrating-to-cloud9-offline#section-step-3-start-docker) in *Migrating a Workspace to Offline*, and then return to this section.\n\n    :exclamation: To run a Docker container that contains a special version of Cloud9 Core with Harvard's CS50-specific plugins, skip the rest of this topic and see [CS50 IDE Offline](https://cs50.readthedocs.io/ide/offline/) instead.\n\n3. Run a container. For instructions, see [Run a new Docker container](using-cloud9-core#section-step-2-run-a-new-docker-container) in Option B, and then return to this section.\n\n## Step 1: Download, install, and run Cloud9 Core\n\n1. Attach to the running Docker container by running the following command.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker exec -it myc9ws /bin/bash\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the preceding command:\n\n* `-it` means to display an interactive terminal for running commands in the container.\n* `myc9ws` is the name of the running container.\n* `/bin/bash` means to use Bash for running commands in the container.\n\n:information-source: On Linux, you might need to add `sudo` before `docker`. To get around this, see [Manage Docker as a non-root user](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user).\n\n2. In the interactive terminal, run the following commands, one at a time, to download, install, and then run Cloud9 Core inside of the container.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"rm -rf /home/ubuntu/workspace/*\\nchown -R ubuntu:ubuntu /home/ubuntu\\ncurl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install nodejs -y\\nexport USER=ubuntu\\nexport C9_PROJECT=c9-offline\\nexport C9_USER=ubuntu\\nexport C9_HOSTNAME=$IP\\nexport C9_PORT=$PORT\\nexport IDE_OFFLINE=1\\nalias c9=/var/c9sdk/bin/c9 > /etc/profile.d/offline.sh\\nsu ubuntu\\ncd /var\\nsudo mkdir c9sdk\\nsudo chown ubuntu:ubuntu c9sdk\\ngit clone https://github.com/c9/core.git c9sdk\\ncd c9sdk\\nscripts/install-sdk.sh\\nsudo chown -R ubuntu:ubuntu /home/ubuntu/workspace/\\nsudo chown -R ubuntu:ubuntu /home/ubuntu/.c9/\\nsudo apt-get install -y ufw\\nsudo ufw allow 5050\\nsudo ufw allow 8080\\nsudo ufw allow 8081\\nsudo ufw allow 8082\\nnode server.js -w /home/ubuntu/workspace/ -a : -l 0.0.0.0 -p 5050\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the preceding commands:\n\n* If port `5050` is already in use on your local computer, replace `5050` in the last command with an available unused port on your local computer. \n\n3. When you're done running the preceding commands, exit the interactive terminal by pressing **Ctrl+P** and then **Ctrl+Q**.\n\n## Step 2: Run the Cloud9 Core IDE\n\nUse your local computer's web browser to go to `http://127.0.0.1:5050/`, which displays the Cloud9 Core IDE. If you replaced `5050` in the preceding last command, use the replacement port here.\n\n:information-source: To display a different directory in the IDE's **Workspace** window, you must reattach to the running Docker container and then stop Cloud9 Core. Then rerun the following command from within the running Docker container, replacing `/home/ubuntu/workspace/` with the path to a different existing directory (and its subdirectories tree) to display in the IDE's **Workspace** window. (Also replace `5050` as needed.) When you're done, be sure to exit the interactive terminal again. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"node server.js -w /home/ubuntu/workspace/ -a : -l 0.0.0.0 -p 5050\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n## Step 3: Commit changes to the Docker container as you work\n\nIf you stop a container, or if the host operating system stops the container for some other reason, any uncommitted changes that you made to that container will be lost. \n\nTo save your changes as you work, you should commit those changes to a new container. For instructions, see [Save new workspace changes as you work](migrating-to-cloud9-offline#section-step-6-save-new-workspace-changes-as-you-work) in *Migrating a Workspace to Offline*.\n\n# See also\n\n* [Running the SDK](https://cloud9-sdk.readme.io/docs/running-the-sdk)\n* [Running Cloud9 Desktop](https://cloud9-sdk.readme.io/docs/running-cloud9-desktop)","excerpt":"","slug":"using-cloud9-core","type":"basic","title":"Using Cloud9 Core"}
You can use Cloud9 to work with code offline on your local desktop or laptop computer by using a special edition of Cloud9 named *Cloud9 Core*. Cloud9 Core uses the Node.js runtime and web browser running on your local computer to display an offline integrated development environment (IDE) that works similar to its c9.io and AWS Cloud9 online counterparts. To use Cloud9 Core, we recommend using one of the following options, which we present in order of increasing time and complexity to set up: * [Option A: Run Cloud9 Core directly](using-cloud9-core#section-option-a-run-cloud9-core-directly) * [Option B: Run Cloud9 Core in a new Docker container](using-cloud9-core#section-option-b-run-cloud9-core-in-a-new-docker-container) * [Option C: Run Cloud9 Core in an existing Docker container](using-cloud9-core#section-option-c-run-cloud9-core-in-an-existing-docker-container) :exclamation: **The information in this topic is not fully supported by Cloud9 or AWS. Use it at your own risk.** We have not fully tested the following information with all operating systems, and we can't guarantee it will work in all situations. Be sure to back up your folders, files, and data, so that you can re-create them, if needed. :question: If you have questions or need help with Cloud9 Core, go to the [Cloud9 Community](https://community.c9.io/) website or email [support@c9.io](mailto:support@c9.io). # Option A: Run Cloud9 Core directly In this approach, you install and then run Cloud9 Core directly on your local computer. When you run Cloud9 Core, you point it to an existing directory (and its subdirectories structure) on your local computer to display in the IDE's **Workspace** window. You then use a web browser on your local computer to display the Cloud9 Core IDE. :information-source: To use Cloud9 Core to to work with code that's inside of a Docker container, see [Option B](using-cloud9-core#section-option-b-run-cloud9-core-in-a-new-docker-container) or [Option C](using-cloud9-core#section-option-c-run-cloud9-core-in-an-existing-docker-container). ## Prerequisites 1. Ensure that the Node.js runtime is installed. To check, from a terminal or command prompt on your local computer, run the command `node --version`. If the Node.js version number isn't displayed, see the following to install Node.js: * **macOS**: [Installing Node.js via package manager: macOS](https://nodejs.org/en/download/package-manager/#macos) or [Installing Node.js Tutorial: macOS](https://nodesource.com/blog/installing-nodejs-tutorial-mac-os-x/) * **Windows**: [Installing Node.js via package manager: Windows](https://nodejs.org/en/download/package-manager/#windows) or [Installing Node.js Tutorial: Windows](https://nodesource.com/blog/installing-nodejs-tutorial-windows/) * **Linux**: [Installing Node.js via package manager](https://nodejs.org/en/download/package-manager/) 2. Ensure that Git is installed. To check, from a terminal or command prompt on your local computer, run the command `git --version`. If the Git version number isn't displayed, install Git by following the steps in [Installing Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). ## Step 1: Download and install the Cloud9 Core 1. From a terminal or command prompt on your local computer, switch to the directory where you want to download Cloud9 Core. This can be any directory that's convenient for you, for example `~`. :information-source: For Windows, `~` is available through utilities such as [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/setup/starting-windows-powershell) and [Git Bash for Windows](https://gitforwindows.org/). Or you can use something like `<drive>:\Users\<user_name>\`. 2. Run the following commands, one at a time, to download and then install Cloud9 Core into the current directory. :information-source: For Windows, we recommend running the following commands by using utilities such as PowerShell or Git Bash for Windows, instead of the built-in **Command Prompt** utility. This is because **Command Prompt** can't run `.sh` files by default. [block:code] { "codes": [ { "code": "git clone https://github.com/c9/core.git c9sdk\ncd c9sdk\nscripts/install-sdk.sh", "language": "shell" } ] } [/block] ## Step 2: Run Cloud9 Core 1. From the `c9sdk` directory in the previous Step 1, run the following command to start Cloud9 Core. [block:code] { "codes": [ { "code": "node server.js -w <starting_directory_path> -a : -l 0.0.0.0 -p 5050", "language": "shell" } ] } [/block] In the preceding command: * `-w` is the relative or absolute path to any existing directory (and its subdirectories tree) to display in the IDE's **Workspace** window. For example, instead of `<starting_directory_path>`, this could be `/Users/<user_name>/` for macOS, `c:\Users\<user_name>\` for Windows, or `/home/<user_name>/` for Linux. * `-a` is the basic auth name and password to use when starting Cloud9 Core, in this case, `:` means don't use any name or password. * `-l` is the IP address for Cloud9 Core to run on, in this case, `0.0.0.0`. * `-p` is the port for Cloud9 Core to run on, in this case, `5050`. If port 5050 is already being used on your local computer, change it to a different port. 2. Use your local computer's web browser to go to `http://127.0.0.1:5050/`, which displays the Cloud9 Core IDE. (If you changed `5050` in the preceding command, change it here also.) :information-source: To display a different directory in the IDE's **Workspace** window, you must stop Cloud9 Core and then restart it with a different `-w` value. To stop Cloud9 Core, you can close the running command's containing window, or you can simply use your operating system's shortcut key combination for stopping the current running command (for example **Ctrl+C** or **Ctrl+X**). If you stop Cloud9 Core, the IDE also stops working. After you restart Cloud9 Core, refresh your web browser to restart the IDE. # Option B: Run Cloud9 Core in a new Docker container In this approach, you use Docker to create a Docker image that contains Cloud9 Core. You run a Docker container based on that image. Then you use a web browser on your local computer to display the Cloud9 Core IDE. :information-source: To use Cloud9 Core to work with code that's inside of an existing running Docker container, see [Option C](using-cloud9-core#section-option-c-run-cloud9-core-in-an-existing-docker-container). ## Prerequisites 1. Install Docker. For instructions, see [Install Docker](migrating-to-cloud9-offline#section-step-2-install-docker) in *Migrating a Workspace to Offline*, and then return to this section. 2. Start Docker. For instructions, see [Start Docker](migrating-to-cloud9-offline#section-step-3-start-docker) in *Migrating a Workspace to Offline*, and then return to this section. :exclamation: To run a new Docker container that contains a special version of Cloud9 Core with Harvard's CS50-specific plugins, skip the rest of this topic and see [CS50 IDE Offline](https://cs50.readthedocs.io/ide/offline/) instead. ## Step 1: Create a Docker image In this step, you create a [Dockerfile](https://docs.docker.com/engine/reference/builder/), which is a text file that describes what Docker needs to create a Docker [image](https://docs.docker.com/engine/docker-overview/#docker-objects). This particular image includes Cloud9 Core. You can also add to this image the settings, packages, apps, and dependencies from one of the default c9.io online workspace types. Once you have a Dockerfile, you can use it to create the image. 1. We recommend creating a blank directory to put the Dockerfile into. For example, this section uses `~/Docker/`. :information-source: For Windows, `~` is available through utilities such as [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/setup/starting-windows-powershell) and [Git Bash for Windows](https://gitforwindows.org/). Or you could use something like `<drive>:\Users\<user_name>\Docker\`. 2. In the blank directory that you created, open a text editor and create a file named `Dockerfile` (with no extension). Add the following contents to this file, and then save it. [block:code] { "codes": [ { "code": "# Replace cloud9/ws-php with any existing Ubuntu-based Docker image ID you want.\nFROM cloud9/ws-php\n\n# Use default answers for all setup prompts.\nENV DEBIAN_FRONTEND noninteractive\n\n# Remove any default PHP debugging settings. \n# Also remove any default workspace files, as they might be replaced later. \nRUN rm -rf /etc/php5/mods-available/xdebug.ini /home/ubuntu/workspace/*\n\n# Add Ruby Version Manager (rvm) to PATH.\nENV PATH=\"/usr/local/rvm/bin/:$PATH\"\n\n# Set ownership defaults.\nRUN chown -R ubuntu:ubuntu /home/ubuntu\n\n# Install Node.js.\nRUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \\\n apt-get install nodejs -y\n\n# Populate environment variables that are required by Cloud9 Core.\nRUN echo \"export USER=ubuntu\\n\\\nexport C9_PROJECT=c9-offline\\n\\\nexport C9_USER=ubuntu\\n\\\nexport C9_HOSTNAME=\\$IP\\n\\\nexport C9_PORT=\\$PORT\\n\\\nexport IDE_OFFLINE=1\\n\\\nalias c9=/var/c9sdk/bin/c9\" >/etc/profile.d/offline.sh\n\nUSER ubuntu\n\n# Download Cloud9 Core into the Docker container.\nWORKDIR /var\nRUN sudo rm -rf c9sdk && \\\n sudo mkdir c9sdk && \\\n sudo chown ubuntu:ubuntu c9sdk && \\\n git clone https://github.com/c9/core.git c9sdk\n\n# Install Cloud9 Core within the Docker container.\nWORKDIR c9sdk\nRUN scripts/install-sdk.sh\n\n# Set additional ownership defaults.\nRUN sudo chown -R ubuntu:ubuntu /home/ubuntu/workspace/ && \\\n sudo chown -R ubuntu:ubuntu /home/ubuntu/.c9/\n\n# Have the Docker container listen to these ports at run time.\nEXPOSE 5050 8080 8081 8082\n\n# Run Cloud9 Core within the Docker container.\nENTRYPOINT [\"node\", \"server.js\", \\\n \"-w\", \"/home/ubuntu/workspace\", \\\n \"--auth\", \":\", \\\n \"--listen\", \"0.0.0.0\", \\\n \"--port\", \"5050\"]", "language": "text" } ] } [/block] 3. In the preceding Dockerfile, replace the following code, and then resave the file: * Replace `cloud9/ws-php` in line 2 with the ID of any existing Ubuntu-based Docker image you want. (It must be an Ubuntu-based image, because this Dockerfile uses Ubuntu-based commands.) For a list of images that represent available default c9.io online workspace types (which are all Ubuntu-based), see the table of base image IDs in [Run the Container](migrating-to-cloud9-offline#section-step-5-run-the-container) in *Migrating a Workspace to Offline*. * If port `5050` is already in use on your local computer, replace `5050` in the last line with any unused port on your local computer. 4. Run the following command to build the image. [block:code] { "codes": [ { "code": "docker build --no-cache -t myc9image:tag_name .", "language": "shell" } ] } [/block] In the preceding command: * `--no-cache` means don't use caching when building the image. * `-t` is a name and optionally a tag for the image. For example, this topic uses `myc9image` as the image's name and `tag_name` as the image's tag. You can use any name and tag you want, but the image's name and tag combination must be unique on your local computer. * `.` (a dot) is the path to the Dockerfile, relative to the current directory. In this case, `.` means the current directory. :information-source: On Linux, you might need to add `sudo` before `docker`. To get around this, see [Manage Docker as a non-root user](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user). Building the image can take a long time. After the command completes, to confirm that your image was successfully built, run the command `docker image ls`. If successful, you'll see an image in the list with a **REPOSITORY** value of **myc9image** and a **TAG** value of **tag_name**. ## Step 2: Run a new Docker container In this step, you use Docker to run a Docker [container](https://docs.docker.com/engine/docker-overview/#docker-objects) that's based on the Docker image you created in the previous Step 1. From a terminal or command prompt on your local computer, run the following command to run the container. [block:code] { "codes": [ { "code": "docker run --privileged -e \"IP=127.0.0.1\" -e \"PORT=8080\" --name myc9ws --mount type=bind,source=<source_path>,target=/home/ubuntu/workspace/ -d -t -p 5050:5050 -p 8080-8082:8080-8082 myc9image:tag_name", "language": "shell" } ] } [/block] In the preceding command: * `--privileged` gives the container permission to do almost everything that the host operating system can do. * `-e` sets simple environment variables in the container, in this case, the IP address and port. * `--name` is a name for the container. * The optional `--mount` option makes a directory available to the container. `source` is the path to the directory on the host operating system (for example, `<source_path>` could be `/Users/<user_name>/` for macOS, `c:\Users\<user_name>\` for Windows, or `/home/<user_name>/` for Linux). `target` is the path in the container that you can use to refer to that same directory (for example, `/home/ubuntu/workspace/`). * `-d` means to run the container in the background. * `-t` means to run the container with a pseudo terminal. * `-p` connects ports in the container to ports on the host operating system. If you replaced `5050` in your Dockerfile, replace `5050:5050` with the replacement port. For example, if you used `9000` in the Dockerfile, use `9000:9000` here. * `myc9image:tag_name` is the name and optional tag of the base image ID to use, which you created in the previous step. To confirm that the container is indeed running, run the command `docker ps`. If it's running, you'll see a container with a **NAMES** value of **myc9ws** and a **STATUS** of **Up** in the list of containers. If it isn't running, try running the command `docker start myc9ws`, and then run `docker ps` again. To see a list of all available containers, regardless of status, run `docker ps -a`. ## Step 3: Run the Cloud9 Core IDE Use your local computer's web browser to go to `http://127.0.0.1:5050/`, which displays the Cloud9 Core IDE. If you replaced `5050` in the Dockerfile and the `docker run` command, use the replacement port here. :information-source: To display a different directory in the IDE's **Workspace** window, you must create a separate image, specifying a different `-w` value in the Dockerfile, and then run a separate container based on that image. Also, if you stop a container that's running Cloud9 Core, the IDE also stops working. After you start or restart a container that's running Cloud9 Core, refresh your web browser to restart the IDE. ## Step 4: Commit changes to the running Docker container as you work If you stop a container, or if the host operating system stops the container for some other reason, any uncommitted changes that you made to that container will be lost. To save your changes as you work, you should commit those changes to a new container. For instructions, see [Save new workspace changes as you work](migrating-to-cloud9-offline#section-step-6-save-new-workspace-changes-as-you-work) in *Migrating a Workspace to Offline*. # Option C: Run Cloud9 Core in an existing Docker container In this approach, you download, install, and run Cloud9 Core in an existing running Docker container. You then use a web browser on your local computer to display the Cloud9 Core IDE. ## Prerequisites 1. Install Docker. For instructions, see [Install Docker](migrating-to-cloud9-offline#section-step-2-install-docker) in *Migrating a Workspace to Offline*, and then return to this section. 2. Start Docker. For instructions, see [Start Docker](migrating-to-cloud9-offline#section-step-3-start-docker) in *Migrating a Workspace to Offline*, and then return to this section. :exclamation: To run a Docker container that contains a special version of Cloud9 Core with Harvard's CS50-specific plugins, skip the rest of this topic and see [CS50 IDE Offline](https://cs50.readthedocs.io/ide/offline/) instead. 3. Run a container. For instructions, see [Run a new Docker container](using-cloud9-core#section-step-2-run-a-new-docker-container) in Option B, and then return to this section. ## Step 1: Download, install, and run Cloud9 Core 1. Attach to the running Docker container by running the following command. [block:code] { "codes": [ { "code": "docker exec -it myc9ws /bin/bash", "language": "shell" } ] } [/block] In the preceding command: * `-it` means to display an interactive terminal for running commands in the container. * `myc9ws` is the name of the running container. * `/bin/bash` means to use Bash for running commands in the container. :information-source: On Linux, you might need to add `sudo` before `docker`. To get around this, see [Manage Docker as a non-root user](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user). 2. In the interactive terminal, run the following commands, one at a time, to download, install, and then run Cloud9 Core inside of the container. [block:code] { "codes": [ { "code": "rm -rf /home/ubuntu/workspace/*\nchown -R ubuntu:ubuntu /home/ubuntu\ncurl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install nodejs -y\nexport USER=ubuntu\nexport C9_PROJECT=c9-offline\nexport C9_USER=ubuntu\nexport C9_HOSTNAME=$IP\nexport C9_PORT=$PORT\nexport IDE_OFFLINE=1\nalias c9=/var/c9sdk/bin/c9 > /etc/profile.d/offline.sh\nsu ubuntu\ncd /var\nsudo mkdir c9sdk\nsudo chown ubuntu:ubuntu c9sdk\ngit clone https://github.com/c9/core.git c9sdk\ncd c9sdk\nscripts/install-sdk.sh\nsudo chown -R ubuntu:ubuntu /home/ubuntu/workspace/\nsudo chown -R ubuntu:ubuntu /home/ubuntu/.c9/\nsudo apt-get install -y ufw\nsudo ufw allow 5050\nsudo ufw allow 8080\nsudo ufw allow 8081\nsudo ufw allow 8082\nnode server.js -w /home/ubuntu/workspace/ -a : -l 0.0.0.0 -p 5050", "language": "shell" } ] } [/block] In the preceding commands: * If port `5050` is already in use on your local computer, replace `5050` in the last command with an available unused port on your local computer. 3. When you're done running the preceding commands, exit the interactive terminal by pressing **Ctrl+P** and then **Ctrl+Q**. ## Step 2: Run the Cloud9 Core IDE Use your local computer's web browser to go to `http://127.0.0.1:5050/`, which displays the Cloud9 Core IDE. If you replaced `5050` in the preceding last command, use the replacement port here. :information-source: To display a different directory in the IDE's **Workspace** window, you must reattach to the running Docker container and then stop Cloud9 Core. Then rerun the following command from within the running Docker container, replacing `/home/ubuntu/workspace/` with the path to a different existing directory (and its subdirectories tree) to display in the IDE's **Workspace** window. (Also replace `5050` as needed.) When you're done, be sure to exit the interactive terminal again. [block:code] { "codes": [ { "code": "node server.js -w /home/ubuntu/workspace/ -a : -l 0.0.0.0 -p 5050", "language": "shell" } ] } [/block] ## Step 3: Commit changes to the Docker container as you work If you stop a container, or if the host operating system stops the container for some other reason, any uncommitted changes that you made to that container will be lost. To save your changes as you work, you should commit those changes to a new container. For instructions, see [Save new workspace changes as you work](migrating-to-cloud9-offline#section-step-6-save-new-workspace-changes-as-you-work) in *Migrating a Workspace to Offline*. # See also * [Running the SDK](https://cloud9-sdk.readme.io/docs/running-the-sdk) * [Running Cloud9 Desktop](https://cloud9-sdk.readme.io/docs/running-cloud9-desktop)