先要生成一個公鑰,使用命令:
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
a6:88:0a:bb:74:70:c6:e0:d5:49:65:e3:04:d5:6c:3e user@workstation.local
把公鑰加入到Heroku
$ heroku keys:add
Uploading ssh public key /home/user/.ssh/id_rsa.pub
若是想刪除公鑰,能夠用命令:
$ heroku keys:remove user@workstation.local
查看公鑰,用命令:
$ heroku keys
如今就能夠建立一個項目了(預先要安裝好rails)。
$ rails myapp
$ git init
$ git add .
$ git commit -m "my first commit"
Created initial commit 5df2d09: my first commit
44 files changed, 8393 insertions(+), 0 deletions(-)
create mode 100644 README
create mode 100644 Rakefile
create mode 100644 app/controllers/application.rb
...
把這個項目建立到Heroku上。
$ heroku create myapp
Enter your Heroku credentials.
Email: user@example.com
Password:
Uploading ssh public key /home/user/.ssh/id_rsa.pub
(當第一次運行heroku命令時,會建立~/.heroku/credentials文件,這個文件記錄了你輸入的用戶名和密碼,這個是在Heroku註冊的用戶名和密碼。)
接下來運行:
$ git push heroku master
Counting objects: 65, done.
Compressing objects: 100% (58/58), done.
Writing objects: 100% (65/65), 80.54 KiB, done.
Total 65 (delta 14), reused 0 (delta 0)
-----> Heroku receiving push
-----> Rails app detected
Compiled slug size is 0.1MB
-----> Launching....... done
App deployed to Heroku
To git@heroku.com:vivid-mountain-91.git
* [new branch] master -> master
再作一個數據庫遷移:
$ heroku rake db:migrate
如今就能夠像日常使用Rails同樣編寫程序了。
更新代碼能夠用:
$ git push herku
將本地數據更新到Heroku網站上:
$ heroku db:push
(這個命令會使用taps,若是沒有安裝,請先安裝。)
要打開網頁瀏覽,就能夠用
$ heroku opengit