This document describes how to set up your workstation to develop for Code.org.
You can do Code.org development using OSX, Ubuntu, or Windows (running Ubuntu in a VM). Setup for Windows is more complicated and relatively few developers use it. Make sure you follow the instructions for your platform in the subsections below.
-
Install OS-specific prerequisites
-
If using HTTPS:
git clone https://github.com/code-dot-org/code-dot-org.git
, if using SSH:[email protected]:code-dot-org/code-dot-org.git
-
gem install bundler -v 1.17
-
rbenv rehash
-
cd code-dot-org
-
bundle install
(Problems running this step? See tips below.) -
bundle exec rake install:hooks
Troubleshoot: `rake aborted!..`
If you have issue "rake aborted! Gem::LoadError: You have already activated rake 12.3.0, but your Gemfile requires rake 11.3.0. Prepending `bundle exec` to your command may solve this." * Follow the instructions and make sure you added `bundle exec` in front of the `rake install:hooks` command
Troubleshoot: wrong version of rake
You might get a message at some point about having the wrong version of rake. If so, try: $> gem uninstall rake $> bundle update rake
-
bundle exec rake install
- This can take a LONG time. You can see if progress is being made by opening up a second shell and starting
mysql -u root
. Run the following command twice, with approximately a 5-10 second delay between each runselect table_schema, table_name, table_rows from information_schema.tables where table_schema like 'dashboard_development' order by table_rows;
If you see a change in the last couple of rows, the install is working correctly.
bundle exec rake build
- This may fail if your are on a Mac and your OSX XCode Command Line Tools were not installed properly. See Bundle Install Tips for more information.
- (Optional, Code.org engineers only) Setup AWS - Ask a Code.org engineer how to complete this step
- Some functionality will not work on your local site without this, for example, some project-backed level types such as https://studio.code.org/projects/gamelab. This setup is only available to Code.org engineers for now, but it is recommended for Code.org engineers.
- Run the website
bin/dashboard-server
- Visit http://localhost-studio.code.org:3000/ to verify it is running.
After setup, read about our code styleguide, our test suites, or find more docs on the wiki.
-
Install Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-
Install Redis:
brew install redis
-
Run
brew install https://raw.github.com/quantiverge/homebrew-binary/pdftk/pdftk.rb enscript gs [email protected] nvm imagemagick rbenv ruby-build coreutils sqlite
Troubleshoot:
Formula.sha1
is disabled orError: pdftk: undefined method sha1' for #<Class:...>
If it complains about `Formula.sha1` is disabled, removing https://raw.github.com/quantiverge/homebrew-binary/pdftk/pdftk.rb from the above command seems to not have serious side effects (it will cause `PDFMergerTest` to fail). It may be a new URL is needed in the dependency list, see https://leancrew.com/all-this/2017/01/pdftk/
Troubleshoot: old version of `<package>`
If it complains about an old version of `<package>`, run `brew unlink <package>` and run `brew install <package>` again
-
Install PhantomJS:
brew cask install phantomjs
-
Set up MySQL
- Force link 5.7 version:
brew link [email protected] --force
- Have
launchd
start mysql at login:ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
- Note, if mysql folder name is "[email protected]", replace the command above by
ln -sfv /usr/local/opt/[email protected]/*.plist ~/Library/LaunchAgents
. (Usels -d /usr/local/opt/mysql*
to check for folder name.)
- Note, if mysql folder name is "[email protected]", replace the command above by
- Start mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
- Note: if this fails check your plist file (
ls ~/Library/LaunchAgents/
) to see if it is "[email protected]". If it is try:launchctl load ~/Library/LaunchAgents/[email protected]
instead
- Note: if this fails check your plist file (
- Force link 5.7 version:
-
Set up rbenv
- Run
rbenv init
- Add the following to
~/.bash_profile
or your desired shell:eval "$(rbenv init -)"
. More info here. - Pick up those changes:
source ~/.bash_profile
- Run
-
Install Ruby 2.5.0
rbenv install 2.5.0
- Set the global version of Ruby:
rbenv global 2.5.0
- Install shims for all Ruby executables:
rbenv rehash
. More info here.
-
Set up nvm
-
Create nvm's working directory if it doesnt exist:
mkdir ~/.nvm
-
Add the following to
~/.bash_profile
or your desired shell configuration file:# Load nvm function into the shell export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh
-
Pick up those changes:
source ~/.bash_profile
-
-
Install Node and yarn
nvm install 8.15.0 && nvm alias default 8.15.0
this command should make this version the default version and print something like:Creating default alias: default -> 8.15.0 (-> v8.15.0)
npm install -g [email protected]
.- (Note: You will have to come back to this step after you clone your repository) Reinstall node_modules
cd apps; yarn; cd ..
-
(El Capitan only) Ensure that openssl is linked:
brew link --force openssl
-
Prevent future problems related to the
Too many open files
error:- Add the following to
~/.bash_profile
or your desired shell configuration file:ulimit -n 8192
- close and reopen your current terminal window
- make sure that
ulimit -n
returns 8192
- Add the following to
-
Install the Xcode Command Line Tools:
xcode-select --install
Troubleshoot: command line tools already installed
If it complains ```xcode-select: error: command line tools are already installed, use "Software Update" to install updates``` check to make sure XCode is downloaded and up to date manually.
-
Install the Java 8 JDK
Ubuntu 16.04 (Download iso) Note: Virtual Machine Users should check the Windows Note below before starting
sudo apt-get update
sudo apt-get install -y git mysql-server mysql-client libmysqlclient-dev libxslt1-dev libssl-dev zlib1g-dev imagemagick libmagickcore-dev libmagickwand-dev openjdk-9-jre-headless libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev curl pdftk enscript libsqlite3-dev phantomjs build-essential redis-server rbenv
- Hit enter and select default options for any configuration popups, leaving mysql passwords blank
- (If working from an EC2 instance)
sudo apt-get install -y libreadline-dev libffi-dev
- Install Node and Nodejs
- Install the latest version of Node Version Manager (nvm)
nvm install v8.15.0 && nvm alias default 8.15.0
Install nodejs v8.15.0node --version
Double check the version of node you are using. If it is wrong, then try restarting your terminal.
- Ensure rbenv and ruby-build are properly installed
- Use the rbenv-doctor from the
rbenv
installation instructions to verify rbenv is set up correctly:- curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
- If there are any errors (they appear red), follow the [
rbenv
installation instructions] (https://github.com/rbenv/rbenv#basic-github-checkout) to properly configurerbenv
, following steps for Ubuntu Desktop so that config changes go into.bashrc
. - Install ruby-build as a rbenv plugin
- Use the rbenv-doctor from the
- Install Ruby 2.5.0 with rbenv
rbenv install 2.5.0
- If your PATH is missing
~/.rbenv/shims
, the next two commands might not work. Edit your .bashrc to include the following line:export PATH="$HOME/.rbenv/bin:~/.rbenv/shims:$PATH"
, then runsource .bashrc
for the change to take effect (as seen in this github issue). rbenv global 2.5.0
rbenv rehash
- Install yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn=1.16.0-1
yarn --version
Double check the version of yarn is correct.
- Finally, configure your mysql to allow for a proper installation. You may run into errors if you did not leave mysql passwords blank
echo "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';" | sudo mysql
- IMPORTANT: Read the following notes, then go back up to the overview and run the commands there.
- If, for any reason, you are forced to interrupt the
bundle exec rake install
command before it completes, cd into dashboard and runbundle exec rake db:drop
before tryingbundle exec rake install
again bundle exec rake install
must always be called from the local project's root directory, or it won't work.- Finally, don't worry if your versions don't match the versions in the overview if you're following this method; the installation should still work properly regardless
- If, for any reason, you are forced to interrupt the
Many Windows developers have found that setting up an Ubuntu virtual machine is less painful than getting Ruby and other prerequisites running on Windows.
- Option A: Use VMWare Player or Virtual Box and an Ubuntu 16.04 iso image
- Maximum Disk Size should be set to 30.0 GB (the default is 20 GB and it is too small)
- Memory Settings for the VM should be 8 GB or higher (Right click the machine -> Settings -> "Memory for this virtual machine" )
- Option B: Use vagrant (install):
- First clone the code.org git repo to get the provided Vagrantfile (you will be able to skip step 1 of the common setup instructions):
git clone https://github.com/code-dot-org/code-dot-org.git
cd code-dot-org
vagrant up
vagrant ssh
- Goto step 2 of the common setup instructions
- First clone the code.org git repo to get the provided Vagrantfile (you will be able to skip step 1 of the common setup instructions):
- Option C: Use an Amazon EC2 instance:
- Request AWS access from [email protected] if you haven't already done so.
- From the EC2 Homepage, click on "Launch Instance" and follow the wizard:
- Step 1: Choose AMI: Select Ubuntu Server 16.04
- Step 2: Choose instance type: Choose at least 8GiB memory (e.g.
t2.large
) - Step 3: Configure Instance: Set IAM Role to
DeveloperEC2
- Step 4: Storage: Increase storage to 32GiB
- Launch the instance. When asked for a key pair, you can create a new key pair (be sure to download and save the .pem file) or use an existing key pair that you have the .pem file for.
- Connect to the instance by selecting the instance in the AWS EC2 dashboard and clicking "Connect". Follow the provided instructions in order to connect via ssh or PuTTY. Upon completing this step, you should be able to connect to your instance via a command like
ssh -i <keyname>.pem <public-dns-name>
. - Optionally, update your ssh config so that you can connect using a shorter command:
- move your private key to
~/.ssh/<keyname>.pem
- add the following lines to ~/.ssh/config:
Host yourname-ec2 Hostname <public-dns-name> User ubuntu PreferredAuthentications publickey IdentityFile ~/.ssh/<keyname>.pem
- run
ssh yourname-ec2
to connect to your instance
- move your private key to
- Go back up to the overview and run the commands there.
- Once you have successfully completed
bundle exec rake build
, you can connect to it as follows:- run
ssh -L 3000:127.0.0.1:3000 yourname-ec2
and then~/code-dot-org/bin/dashboard-server
on your local machine. This sets up SSH port forwarding from your local machine to your ec2 dev instance for as long as your ssh connection is open. - navigate to http://localhost-studio.code.org:3000/ on your local machine
- run
Note: the installation process now enables this by default, which is recommended. You can manually edit these values later if you want to disable local JS builds.
If you want to make JavaScript changes and have them take effect locally, you'll want to enable local builds of the JavaScript packages. You'll need to do this once:
-
Edit locals.yml and enable the following options:
# code-dot-org/locals.yml # These enable the local apps build build_apps: true use_my_apps: true
-
Run
bundle exec rake package
for the changes to take effect.
This configures dashboard to rebuild apps whenever you run bundle exec rake build
and to use the version that you built yourself. See the documentation in that directory for faster ways to build and iterate.
If waiting around for javascript builds is making you sad, consider sending build time logs to New Relic so we can track the slowness. You can do this by copying our license key from the New Relic account page and pasting it into locals.yml
:
new_relic_license_key: <license key here>
We enforce linting rules for all our code, and we recommend you set up your editor to integrate with that linting.
We use eslint to lint our Javascript; see the official integrations guide for instructions for your editor of choice.
Our lint configuration uses formatting rules provided by Prettier. You can configure your editor to auto-format your code to meet our requirements, in addition to the error highlighting provided by eslint. See the official integrations guide for instructions for your editor of choice.
We use RuboCop to lint our Ruby; see the official integrations guide for instructions for your editor of choice.
Please also see our other documentation, including our:
Wondering where to start? See our contribution guidelines for more information on helping us out.
If rmagick doesn't install, check your version of imagemagick, and downgrade if >= 7
convert --version
brew install imagemagick@6
brew unlink imagemagick
brew link imagemagick@6 --force
If you continue to have issues with rmagick, after changing your imagemagick version, you may need to uninstall/reinstall the gemgem uninstall rmagick
gem install rmagick -v 2.15.4
If you run into an error with libv8 while running bundle install
- Uninstall libv8:
gem uninstall libv8
- Make sure the gem no longer exists with:
gem list libv8
- Install the current version used in code.org repo:
gem install libv8 -v CURRENT_CODEORG_VERSION -- --with-system-v8
(you can find what to fill in for CURRENT_CODEORG_VERSION as the current version of libv8 in the Gemfile.lock).
If you run into an issue about mysql2 while running bundle install
and the error output includes "ld: library not found for -lssl" try :
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
(Steps from this github issue)
If you run into an issue about therubyracer while running bundle install
try :
gem uninstall libv8
gem install therubyracer -v CURRENT_CODEORG_VERSION
(you can find what to fill in for CURRENT_CODEORG_VERSION as the current version of the therubyracer in the Gemfile.lock).gem install libv8 -v CURRENT_CODEORG_VERSION -- --with-system-v8
(You can find what to fill in for CURRENT_CODEORG_VERSION as the current version of libv8 in the Gemfile.lock).
(Steps from this stackoverflow question)
If you run into the error message can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)
while running bundle install
try (as seen in this StackOverflow):
gem install bundler -v BUNDLED_WITH_VERSION
, where the version is theBUNDLED WITH
version in Gemfile.lock).bundle install
OS X: when running bundle install
, you may need to also run xcode-select --install
. See stackoverflow. If this doesn't work, step 9 in the overview will not run correctly. In that case run the following command in the Terminal (found from
nodejs/node-gyp#569): sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
While it's possible to run the server locally without these, we've found the following hardware specifications to be best for fast development.
- Memory: minimum of 8GB RAM for
dashboard-server
andyarn
- Storage: The repository takes up 16GB