首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Ubuntu中启动Nodejs/Angularjs应用

在Ubuntu中启动Nodejs/Angularjs应用
EN

Stack Overflow用户
提问于 2014-12-12 22:32:38
回答 4查看 3.5K关注 0票数 0

我刚刚读了Angularjs的教程,想从http://tinyurl.com/AngularJSDemos运行测试应用程序(由(C) Wahlin Consulting提供)。其自述文件告知:

代码语言:javascript
运行
复制
NODE.JS OPTION:

If you want to run the site using Node.js (install it from http://nodejs.org) run the following at the command-prompt from within the AngularJSDemos folder:

node server.js

Now navigate to http://localhost:8080/DemoList.html or     http://localhost:8080/CustomerManagementApp in your browser.

我已经安装了nodejs,并尝试在我的Ubuntu系统中从终端启动它:

代码语言:javascript
运行
复制
mainuser@mylaptop:~$ cd /home/mainuser/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos/
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ node server.js
The program 'node' can be found in the following packages:
 * node
 * nodejs-legacy
Try: sudo apt-get install <selected package>
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ sudo apt-get install node

...

mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ node server.js
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ node server.js
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ node
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ node ./server.js &
[1] 11153
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ node ./server.js
[1]+  Exit 1                  node ./server.js
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ node ./server.js
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ sudo apt-get install nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
nodejs is already the newest version.
The following packages were automatically installed and are no longer required:
  kde-l10n-engb kde-l10n-pl linux-headers-3.13.0-32
  linux-headers-3.13.0-32-generic
Use 'apt-get autoremove' to remove them.
0 to upgrade, 0 to newly install, 0 to remove and 28 not to upgrade.
mainuser@mylaptop:~/Ebooks/AngularJS/AngularJSDemos/AngularJSDemos$ 

但是无论我做什么,我都不能启动这个示例。在Chrome中“此网页不可用”,在Firefox中“无法连接”。此外,看起来我根本不能在终端中启动它。

如何启动此示例?

EN

回答 4

Stack Overflow用户

发布于 2014-12-12 22:38:31

我建议使用nvm来安装node并在您的系统上管理不同的版本。

这很简单:

代码语言:javascript
运行
复制
# First, we need to clone the nvm repository:
$ git clone https://github.com/creationix/nvm.git ~/.nvm

# Then, we need to add the following line to our .profile, .bashrc or .zshrc:
$ echo "source ~/.nvm/nvm.sh" >> .zshrc

安装nvm是不够的,我们现在需要安装node & npm。

代码语言:javascript
运行
复制
# To print out the list of all the available versions, simply run:
$ nvm ls-remote

# We want to install the current stable version which is v0.10.26, so we need to run:
The -s flag means we want to compile node from source.
$ nvm install -s v0.10.30

当安装过程完成后,我们全新的节点和npm将被安装!nvm的伟大之处在于,您可以在每个shell实例中使用不同版本的node。但如果您想坚持使用最新版本,可以通过运行以下命令将其设置为默认版本:

代码语言:javascript
运行
复制
$ nvm alias default 0.10.30

通过键入node -v && npm -v确保一切都已启动并运行

票数 1
EN

Stack Overflow用户

发布于 2015-05-09 17:26:47

这里有一个不同的方法来解决这个问题,本教程建议使用npm,这是很好的。但这需要时间,互联网连接和设置。这是另一种方法,如果你已经在使用Ubuntu,python应该已经安装在你的系统中了。您的python安装已经附带了一个简单的HTTP服务器,您可以使用它来运行angular应用程序。

在控制台中,键入python -m SimpleHTTPServer 8080

然后将您的浏览器指向localhost:8080

并找到你的angular项目。那么它应该可以正常运行。

票数 1
EN

Stack Overflow用户

发布于 2015-05-09 17:36:22

您可能安装了incorrect node package

多亏了这一点,您的node命令并不等同于nodejs,而是调用了完全不同的东西。

尝试使用

代码语言:javascript
运行
复制
nodejs ./server.js
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27445846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档